[英]Email: How to show only Display name for the From Address?
I am writing a C# tool which send out email report. 我正在编写一个C#工具,可以发送电子邮件报告。 While sending the email report,I configure From and To address.
发送电子邮件报告时,我配置发件人和收件人地址。
To address is automatically resolved to outlook Display name when delivered. 交货时,地址自动解析为Outlook显示名称。
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
从Web.Config中的电子邮件友好显示名称存储Smtp
This displays the mail address as My Name <MyName@MyCompany.com> 这会将邮件地址显示为我的名字<MyName@MyCompany.com>
However, I Just want to see only My Name similar to a mail when I send it from outlook. 但是,当我从Outlook发送邮件时,我只想只看到类似于邮件的“ 我的名字” 。
Any help would be much appreciated. 任何帮助将非常感激。
You can specify display names while instantiating MailAddress class. 您可以在实例化MailAddress类时指定显示名称。 ex.
恩。 MailAddress from = new MailAddress("ben@contoso.com", "Ben Miller");
来自的邮件地址= new MailAddress(“ ben@contoso.com”,“ Ben Miller”); Check below URL for sample code
检查下面的URL以获取示例代码
http://msdn.microsoft.com/en-us/library/system.net.mail.mailaddress.displayname.aspx http://msdn.microsoft.com/en-us/library/system.net.mail.mailaddress.displayname.aspx
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. 目前尚不清楚您现在使用什么代码...无论如何,如果要使Outlook自动化 ,则需要使用Recipients.Add方法添加收件人(To,Cc或Bcc),然后调用Resolve或ResolveAll方法。
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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.