I'm writing a timer job which once complete it sends out an email from noreply@company.com, when it arrives in outlook it shows that address as the from person.
Is there a way to get it to display a 'display name'. For example all emails received from me would show Paul Matthews not paul.matthews@company.com. (Which I know in this instance is probably more to do with AD and Exchange).
The code I'm using is below.
var emailFromAddress = _properties["EmailFromAddress"].ToString();
var emailToAddress = _properties["EmailDistributionGroup"].ToString();
var webAddress = _properties["WebSiteOfLibrary"].ToString();
var subject = "New Report - " + DateTime.Now.ToString("dd MMM yyyy");
StringDictionary messageHeader = new StringDictionary();
messageHeader.Add("to", emailToAddress);
messageHeader.Add("from", emailFromAddress);
messageHeader.Add("subject", subject);
messageHeader.Add("content-type", "text/html");
using (SPSite site = new SPSite(webAddress))
{
using (SPWeb web = site.OpenWeb())
{
DateTime timeNow = DateTime.Now;
var sb = new StringBuilder();
sb.Append(
"<STYLE TYPE='text/css'>body, html{font-color:#000;font-family:arial;font-size:8.0pt}</STYLE>");
sb.AppendFormat("<div style='font-size:11pt;font-family:calibri'>Results between {0} and {1}</div><br/><br/>", LastRun.ToString("dd MMM yyyy hh:mm tt"), timeNow.ToString("dd MMM yyyy h:mm tt"));
sb.AppendFormat("<div style='font-size:11pt;font-family:calibri'>Total: {0}<br/><br/>", total);
sb.AppendLine(HTMLResults);
SPUtility.SendEmail(web, messageHeader, sb.ToString());
}
}
The thing is, the email address has to be noreply@company.com which we will use this for multiple applications, so the display name should reflect a name of the application.
