I'm about to deploy my first ASP.NET website to Azure: There is a contact form in my website with 4 text boxes (email, name, subject and body) and send button. I use this configuration to send emails:

 <system.net>
    <mailSettings>
      <smtp deliveryMethod="Network" from="Mohamed &lt;name@outlook.com&gt;">
        <network host="Smtp.live.com" port="587" enableSsl="true" userName="name@outlook.com" password="mypassword"/>
      </smtp>
    </mailSettings>
  </system.net>

And this is the handler for the send button

protected void Button1_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            string fileName = Server.MapPath("~/App_Data/Message.txt");
            string mailBody = File.ReadAllText(fileName);

            mailBody = mailBody.Replace("##Name##", TextBoxName.Text);
            mailBody = mailBody.Replace("##Email##", TextBoxEmail.Text);
            mailBody = mailBody.Replace("##Subject##", TextBoxSubject.Text);
            mailBody = mailBody.Replace("##Body##", TextBoxBody.Text);
            MailMessage visitorMessage = new MailMessage();
            visitorMessage.Subject = "New Message: " + TextBoxSubject.Text;
            visitorMessage.Body = mailBody;

            visitorMessage.From = new MailAddress(TextBoxEmail.Text, TextBoxName.Text);
            visitorMessage.To.Add(new MailAddress("name@outlook.com", "Mohamed"));
            visitorMessage.ReplyToList.Add(new MailAddress(TextBoxEmail.Text));
            SmtpClient mySmtpClient = new SmtpClient();
            mySmtpClient.Send(visitorMessage);
            LabelIRespond.Visible = true;

        }
    }

I use these settings for the IIS server, obviously it's not working with production server. Please tell me what changes should I make to enable this function?

EDIT when I send message from the form, The process doesn't complete, and I receive a privacy warning to my email.

Related posts

Recent Viewed