I am using surface controller to send the email.I define the “From Email” ([email protected]) hard coded. But now I want that the admin update the “From Email” field whenever they want.so How can I get the value of email field from admin panel using Datatype. /umbraco.
MailAddress from = new MailAddress(“[email protected]”,
“testproject”);
[HttpPost]
public int SendMail(MessageModel model)
{
if (ModelState.IsValid)
{
try
{
string subject = "From: " + model.Email;
string body = model.Message;
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential("[email protected]", "abc123#!")
};
body = PopulateEmailBody(model.Name, model.Email, model.Mobile, model.Message);
MailAddress from = new MailAddress("[email protected]", "testproject");
MailAddress to = new MailAddress(model.Email,model.Name);
MailMessage message = new MailMessage(from, to);
message.Subject = subject;
message.IsBodyHtml = true;
message.Body = body;
SmtpClient client = smtp;
client.Send(message);
//TempData.Add("Success", true);
return 1;
}
catch (Exception ex)
{
return -1;
}
}
else
return -1;
}
This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/85528-send-email-from-contact-us-form