1

I am writing a C# tool which send out email report. While sending the email report,I configure From and To address.

To address is automatically resolved to outlook Display name when delivered.

However, From address does not resolve it. On analyzing across the board,I come across this thread. Storing Smtp from email friendly display name in Web.Config

This displays the mail address as My Name <MyName@MyCompany.com>

However, I Just want to see only My Name similar to a mail when I send it from outlook.

Any help would be much appreciated.

Community
  • 1
  • 1
karpanai
  • 235
  • 4
  • 14
  • possible duplicate of [Storing Smtp from email friendly display name in Web.Config](http://stackoverflow.com/questions/1394354/storing-smtp-from-email-friendly-display-name-in-web-config) – Hussein Khalil May 19 '15 at 14:07
  • No, I mentioned that link already in my question.My question is different. All I want is "From" address should be resolved like "To" address – karpanai May 20 '15 at 08:49
  • @karpanai : Maybe the way it gets displayed depends on the email viewer (and outlook shows it differently than gmail/yahoo/...)? – stomy Mar 27 '18 at 19:37

2 Answers2

0

You can specify display names while instantiating MailAddress class. ex. MailAddress from = new MailAddress("ben@contoso.com", "Ben Miller"); Check below URL for sample code

http://msdn.microsoft.com/en-us/library/system.net.mail.mailaddress.displayname.aspx

Romero
  • 53
  • 5
0

It is not clear what code you use now... Anyway, if you automate Outlook you need to use the Recipients.Add method for adding recipients (To, Cc or Bcc) and then call the Resolve or ResolveAll methods.

private void SetRecipientTypeForMail()
{
    Outlook.MailItem mail = Application.CreateItem(
      Outlook.OlItemType.olMailItem) as Outlook.MailItem;
    mail.Subject = "Sample Message";
    Outlook.Recipient recipTo =
      mail.Recipients.Add("someone@example.com");
    recipTo.Type = (int)Outlook.OlMailRecipientType.olTo;
    Outlook.Recipient recipCc =
      mail.Recipients.Add("someonecc@example.com");
    recipCc.Type = (int)Outlook.OlMailRecipientType.olCC;
    Outlook.Recipient recipBcc =
      mail.Recipients.Add("someonebcc@example.com");
    recipBcc.Type = (int)Outlook.OlMailRecipientType.olBCC;
    mail.Recipients.ResolveAll();
    mail.Display(false);
}
Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • Hi, this is again for resolving "To" address.. I am wondering whether is there any way to resolve "From" address – karpanai May 20 '15 at 14:20
  • It doesn't matter where it should be used - from or to. You need to created a recipient object and use the resolve method. `Set myRecipient = myNamespace.CreateRecipient("Dan Wilson") ` `myRecipient.Resolve` – Eugene Astafiev May 20 '15 at 14:25
  • hi, I am using MailMessage class, as described in the link http://stackoverflow.com/questions/449887/sending-e-mail-using-c-sharp. How do I convert "outlook recipient" to "from address" of MailMessage – karpanai May 21 '15 at 09:07
  • The Outlook object model doesn't provide such class. It seems the question is not related to Outlook. – Eugene Astafiev May 21 '15 at 11:52
  • I removed the Outlook tag from the question. – Eugene Astafiev May 21 '15 at 14:30