I recently developed a code as part of a contact page in a website which needed to send email here is the code.
var sender = contact.Email;
var email = new MailMessage();
email.To.Add(new MailAddress("arnaldo.skywalker@caudal.cu"));
email.From = new MailAddress("arnaldo@caudal.cu");
email.Subject = form["Tipo de contacto"] + " de " + sender;
email.Body = contact.Message;
email.IsBodyHtml = true;
email.Priority = MailPriority.Normal;
var smtp = new SmtpClient
{
Host = "192.168.145.209",
Port = 25,
EnableSsl = false,
UseDefaultCredentials = false,
Credentials = new NetworkCredential("arnaldo@caudal.cu", "lade$23")
};
try
{
smtp.Send(email);
var verificationEmail = new MailMessage();
verificationEmail.To.Add(new MailAddress(sender));
verificationEmail.From = new MailAddress("arnaldo@caudal.cu");
verificationEmail.Subject = "Su " + form["Tipo de contacto"] + " será atendida " + sender;
verificationEmail.Body = "Atenderemos su " + form["Tipo de contacto"] + " a la mayor brevedad posible";
verificationEmail.IsBodyHtml = true;
verificationEmail.Priority = MailPriority.Normal;
smtp.Send(verificationEmail);
email.Dispose();
verificationEmail.Dispose();
ViewData["Message"] = "Su mensaje ha sido enviado satisfactoriamente";
}
catch (Exception)
{