tags:

views:

241

answers:

2

I'm trying to build a little WPF email sender tutorial but I don't want to share it if it has this glaring bug.

Currently, this is what happens.

  1. user types in username and password.
  2. label 'loginstatus' changes to "Logged in" regardless if it's gibeerish or not.
  3. Message body and send to fields are enabled.
  4. user pressed "Send" button and if there is an exception (for example, wrong username/password) the messagebox shows it, and loginstatus is changed back to logged out.

This is very very wrong and I want to fix it.

How can I just 'ping' to see if a credential is correct (without sending a test email).

I'm using smtp.gmail.com port 587

Edit Here's how I'm sending the emails.

var client = new SmtpClient("smtp.gmail.com", 587)
        {
            Credentials = new NetworkCredential(username, password),
            EnableSsl = true
        };

        try
        {
            client.Send(fromEmail, toEmail, subject, body);
        }
        catch (Exception e)
        {
            MessageBox.Show(e.Message);                
        }       
A: 

If you have control over the SMTP communication you can only do the login part to test username and password without sending a message.

David Schmitt
How would I do the login part only?
Sergio Tapia
Since you are using the submission port (587), the needed commands would be EHLO, STARTTLS and AUTH. Implementing them by hand is pretty expensive, since you have to upgrade the connection to SSL with STARTTLS. See http://tools.ietf.org/html/rfc5321 (EHLO), http://tools.ietf.org/html/rfc3207 (STARTTLS) and http://tools.ietf.org/html/rfc2554 (AUTH)
David Schmitt
A: 

Hi, You can't do this with System.Net.Mail. You have to either roll your own or used a 3rd party product (shameless plug: like mine-- www.aspnetmx.com )

Cheers!

Dave

dave wanta