0

I have deployed my website to azure cloud and I am trying to send emails to my client. When I have tested this on local host it works properly but on moving to cloud it shows several errors like sometimes:

-> connection time out and i have declared timeout as 150000

->The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. (I have made less secure app allowed to mail account)

Here I am attaching my code. Please review it and suggest a way to resolve it. Thank you all in advance.

protected void Button2_Click(object sender, EventArgs e)
{

    MailMessage msg = new MailMessage();
    MailAddress from = new MailAddress("bvpcsccloud@gmail.com");
    MailAddress to = new MailAddress(Label7.Text);
    string subjectText = "E-appointment request";
    string bodyText = @"Hi, This mail is for the request of e-appointment from our patient:"+TextBox4.Text.ToString()+"<br />"+ "The patient has age:";
    bodyText +=  TextBox5.Text.ToString()+"<br /> Disease symbols are"+TextBox2.Text.ToString()+"<br /> Disease name:"+ TextBox3.Text.ToString();
    bodyText += "<br />Patient address is" + TextBox1.Text.ToString();
    bodyText += "<br /> preffered date choosen by patient is" + DropDownList1.SelectedItem.Text + "-" + DropDownList2.SelectedItem.ToString() + "-" + DropDownList3.SelectedItem.Text;
    msg.To.Add(to);
    msg.From = from;
    msg.Subject = subjectText;
    msg.Body = bodyText;
    msg.IsBodyHtml = true;
    SmtpClient smtp = new SmtpClient();
    smtp.Host = "smtp.gmail.com";
    smtp.Port = 587;



   //smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
    smtp.Credentials = new System.Net.NetworkCredential("bvpcsccloud@gmail.com", "password");

    //smtp.UseDefaultCredentials = false;
    try
    {
        smtp.EnableSsl = true;
        smtp.Timeout = 150000;
        smtp.Send(msg);

        smtp.Dispose();
        Response.Redirect("~/appointment_booked.aspx");
    }
    catch (Exception ex)
    {
        throw ex;

    }
} 
Ben Kane
  • 9,331
  • 6
  • 36
  • 58
  • 1
    I initially thought this was a duplicate, but perhaps not--this one seems to be Azure-related, as the code's already working in the on-premises environment. @Bhavesh Gupta, to get further I think you'll need to edit your post to provide better error details. (Paste in the exact errors.) – Reg Edit May 07 '15 at 17:03
  • I encountered an SMTP server issue once that was only reproducible when the client was in Azure. You can compare with my problem+solution here: http://stackoverflow.com/questions/17371311/ – Mike Asdf May 07 '15 at 20:42

0 Answers0