简体   繁体   English

电子邮件:如何仅显示发件人地址的显示名称?

[英]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),然后调用ResolveResolveAll方法。

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.

相关问题 如何将格式化的 email 地址解析为显示名称和 email 地址? - How to parse formatted email address into display name and email address? 来自 SSIS 脚本任务的电子邮件 - 显示发件人姓名而不是地址 - Email from SSIS Script Task - Show sender name instead of address 仅传递电子邮件地址时,从EWS获取显示名称 - Getting display name from EWS when passing in just an email address 如何从电子邮件地址获取SMTP主机名? - How can I get the SMTP host name from email address? 从电子邮件地址获取域名 - Get domain name from an email address 使用C#,地址拆分,仅显示郊区名称 - using C#, address split and only display suburbs name 如何验证 TextEdit 以仅接受来自 .cs 文件的 WPF 中的网站地址、电话、电子邮件格式? - How to Validate TextEdit to accept Website address,Phone,Email formats only in WPF from .cs file? 如何在FolderBrowserDialog的文本框中仅显示文件夹名称而不是路径? - How to only display folder name instead of path, in textbox from FolderBrowserDialog? 使用 Active Directory 中的 email 地址查找域名 - find domain name using email address from Active Directory 如何更改电子邮件地址字段? - How to change email FROM address field?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM