1

I created gmail account to use it to send mails but no any mails (without any exception) sent code snippet:

public static bool SendEmail(string _FromEmail, string _ToEmail, string _Subject, string _EmailBody) {

    try
    {


        SmtpClient smtpClient = new SmtpClient();
        smtpClient.Host = "smtp.gmail.com";
        smtpClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
        smtpClient.Port = 465;
        smtpClient.Credentials = new NetworkCredential("my gmail account", "my password");
        smtpClient.EnableSsl = false;
        smtpClient.UseDefaultCredentials = false;
        MailMessage msg = new MailMessage();
        msg.From = new MailAddress(_FromEmail);
        msg.To.Add(new MailAddress(_ToEmail));
        msg.Subject = _Subject;
        msg.Body = _EmailBody;
        msg.IsBodyHtml = true;

        smtpClient.Send(msg);

        return true;
    }
    catch (Exception ex)
    {
        if (ex.InnerException != null)
        {
            String str = ex.InnerException.ToString();

        }
        return false;
    }



}

1 Answer 1

1

I'm not an ASP.net guy. But let me tell you something to try. Try using STARTTLS on port 587. I've got the same problem with java and I could get it solved by using STARTTLS.

Have a look at this page

Good luck.

2
  • when i tried to set smtpClient.EnableSsl = true; I got this exception: [System.Net.Mail.SmtpException] = {"SSL must not be enabled for pickup-directory delivery methods."} Jun 26, 2011 at 13:31
  • don't enable ssl. you have to enable starttls. i'm sorry i don't know how to do that in asp.net. in java we enable strattls and authentication by "properties.put("mail.smtp.starttls.enable", "true"); properties.put("mail.smtp.auth", "true");" Try to find how to implement the same thing in asp.net
    – Bee
    Jun 27, 2011 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.