In my search for a way to send email on my webapp through a form, the only solution I got working was an old MSDN solution for a WebMail helper where it had me hardcode the credentials for an email to send through.
Right, off the bat, I know this is not ideal. Is there an easy way to send this mail out from a WebMail default so I can remove the login credentials and not look so amateurish???
@{
var customerName = Request["customerName"];
var customerEmail = Request["customerEmail"];
var customerPhone = Request["customerPhone"];
var customerRequest = Request["customerRequest"];
var errorMessage = "";
var toMail = "user@mail.com";
var debuggingFlag = false;
try
{
// Initialize WebMail helper
WebMail.SmtpServer = "smtp.gmail.com";
WebMail.SmtpPort = 587;
WebMail.UserName = "user@mail.com";
WebMail.Password = "Password!";
WebMail.From = "user@mail.com";
WebMail.EnableSsl = true;
// Send email
WebMail.Send(to: toMail,
subject: "Quote/Info request from - " + customerName,
body: customerPhone + customerRequest
);
}
catch (Exception ex)
{
errorMessage = ex.Message;
}