Sharepoint - SPUtility Sending Email with display name
Might I suggest switching to using the System.Net.Mail.MailMessage object instead of SPUtility. SPUtility.SendEmail
is a good shortcut but, as you've seen, you lose a lot of control over how the message is sent and formatted. The MailMessage
object gives you that back but does require just a tiny bit more work.
To answer your specific question, the MailAddress object handles the formatting of the email address and name combination so you would have to use your application name as the 'fromname
' below.
MailMessage msg = new MailMessage();
msg.From = new MailAddress(web.Site.WebApplication.OutboundMailSenderAddress, fromName);
msg.To.Add(new MailAddress(to));
msg.Subject = subject;
msg.Body = message;
msg.IsBodyHtml = true;
msg.BodyEncoding = System.Text.Encoding.UTF8;
SmtpClient server = new SmtpClient(web.Site.WebApplication.OutboundMailServiceInstance.Server.Address);
server.Send(msg);
If you want to customize the sender email address, then you cannot use SPUtility.SendEmail -- you'll have to use the System.Net.Mail framework classes.
Under the covers, SPUtility calls a method named "RemoveFriendlyNameFromEmailAddress" :(