Question

I've been trying to add a support service for one of my apps, so I decided to write a method that sends the user feedback to my personal email. According to MSDN:

If the UseDefaultCredentials property is set to false and the Credentials property has not been set, then mail is sent to the server anonymously.

But when I set the UseDefaultCredentials to false, nothing is delivered to my email:

        MailMessage mail = new MailMessage("MyEmail@gmail.com", "MyEmail@gmail.com");
        SmtpClient client = new SmtpClient();
        client.Port = 25;
        client.DeliveryMethod = SmtpDeliveryMethod.Network;
        client.UseDefaultCredentials = false;
        client.Host = "smtp.google.com";
        mail.Subject = "this is a test email.";
        mail.Body = "this is my test email body";
        client.Send(mail)

My question is that, is this issue related to Gmail or is there anything wrong with the way I'm doing this.

Was it helpful?

Solution

Without more detail, it is hard to be sure what the problem is. Does it work if you set UseDefaultCredentials to true?

Standard problems to watch out for with SMTP:

  • Most ISP's block port 25, so you cannot use non-SSL/TLS SMTP except to a local server or in special cases.

  • GMail's SMTP, as far as I know, only accepts authenticated login for mail transmission.

In my experience, using an authenticated gmail account (with password) and an TLS (encrypted) connection (not port 25) works fine from almost anywhere, but probably won't be desirable for your application since you do not have the user's gmail credentials.

A standard alternative approach you might consider if all this is to much of a hassle is to support your own forms-based feedback submission process on your own web site, as opposed to generic email.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top