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;
}
you could add a property called "To emailaddress" somewhere in your Umbraco node structure and read this property in your function. This is standard Umbraco-code that you could use.
We've faced the same problem where editors require they can change almost anything for their emails (to, from, cc, bcc, subject, content, etcetera). We developed a package for that, called PerplexMail (https://our.umbraco.org/projects/backoffice-extensions/perplexmail-for-umbraco/).
Just an observation, if you are wanting to allow the editors to change the from address, they must also be able to change the login credentials as you are sending via Gmail.
If your from address isn't the address you are logging into the Google mail server with then I believe Google with reject the mail and not allow you to send it.
Send Email From Contact Us Form
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.
Hi Navneet,
you could add a property called "To emailaddress" somewhere in your Umbraco node structure and read this property in your function. This is standard Umbraco-code that you could use.
We've faced the same problem where editors require they can change almost anything for their emails (to, from, cc, bcc, subject, content, etcetera). We developed a package for that, called PerplexMail (https://our.umbraco.org/projects/backoffice-extensions/perplexmail-for-umbraco/).
Maybe it's an option for your project too,
regards,
Jeffrey
Hi Navneet,
Just an observation, if you are wanting to allow the editors to change the from address, they must also be able to change the login credentials as you are sending via Gmail.
If your from address isn't the address you are logging into the Google mail server with then I believe Google with reject the mail and not allow you to send it.
Thanks,
Nik
is working on a reply...