1

Possible Duplicate:
Sending email through Gmail SMTP server with C#

The following is the asp code triggered by a button click. I am working on windows 7 home premiun. I get the error 'The operation has timed out' have also tried port 587 but get the error 'The SMTP server requires a secure connection or the client was not authenticated. '

    public void SendEmailFromCommAgent(string subject, string body, string to)
    {

        try
        {
            SmtpClient mc = new SmtpClient("smtp.gmail.com",465);
            MailMessage msg = new MailMessage("xxxxxxx@gmail.com", to, subject, body);
            mc.EnableSsl = true;
            mc.UseDefaultCredentials = false;
            mc.Credentials = new System.Net.NetworkCredential("xxxxxxxxxxxx@gmail.com", "xxxxxxxxxxxxxxx");
            msg.From = new MailAddress("xxxxxxxxxxx@gmail.com");
            mc.DeliveryMethod = SmtpDeliveryMethod.Network;
            mc.Timeout = 50000;
            msg.IsBodyHtml = true;

            mc.Send(msg);
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }

IIS configuration email adddress: xxx@gmail.com smtp server : smtp.gmail.com port : 465 specify credentials: username xxxxx@gmail.com password xxxxxxx

any help would be great :)

Community
  • 1
  • 1
  • 1
    Had you configured two-step verification gmail account? If yes then use application-key in place of password. – KV Prajapati Nov 24 '12 at 02:47
  • ah thanks never thought of that one – user1848817 Nov 24 '12 at 02:53
  • yes thanks changed it back to 587 and worked with the application specific key. Sorry for the duplicate post have been searching for the last 4 hours and was just going round in circles and new I must be missing something simple. – user1848817 Nov 24 '12 at 03:12

0 Answers0