【问题标题】:I want to display only Display Name than Display Name with Mail ID我只想显示显示名称而不是带有邮件 ID 的显示名称
【发布时间】:2026-02-05 14:10:01
【问题描述】:

我创建了一个 Web 服务(Windows server 2018 R2 企业版),我在其中使用代码发送邮件

public void SendMail(string f, string t, string subject, string body)
{
    System.Web.Mail.MailMessage Message = new System.Web.Mail.MailMessage();
    Message.From = f;
    Message.To = t;
    Message.Subject = subject;
    Message.Body = body;
    Message.BodyFormat = MailFormat.Html;
    System.Web.Mail.SmtpMail.SmtpServer = "smtp.Company.com";
    System.Web.Mail.SmtpMail.Send(Message);
}

当从地址触发的邮件类似于“Suresh Kukka”(显示名称)时

如果我使用托管相同 Web 服务的相同代码(Windows Server 2016 Standard),我会收到来自“suresh.kukka@company.com”之类地址的邮件

我使用了如下新代码(托管在 Windows Server 2016 Standard 中的 Web 服务)

public void SendMail(string f, string t, string subject, string body)
{ 
    System.Net.Mail.MailMessage Message = new System.Net.Mail.MailMessage();
    string[] name = f.Split('@');
    string[] mainname = name[0].Split('.');
    string DisplayName = mainname[0] + " " + mainname[1];
    TextInfo _textinfo = new CultureInfo("en-US", false).TextInfo;
    DisplayName = _textinfo.ToTitleCase(DisplayName);
    // Message.From = f;
    MailAddress address = new MailAddress(f, DisplayName);
    Message.From = address;


    Message.To.Add(t);
    Message.Subject = subject;
    Message.Body = body;
    Message.IsBodyHtml = true;


    SmtpClient objclint = new SmtpClient();
    objclint.EnableSsl = true;
    objclint.Port = 25;
    objclint.Host = "smtp.company.com";
    objclint.Send(Message);
    Message.Dispose();

}

我在这里收到来自 Suresh Kukka leq Suresh.kukka@company.com geq 之类的地址的邮件,但我只想要像“Suresh Kukka”这样的地址......有人可以帮我吗

【问题讨论】:

  • 将 SSL 绑定应用于 Web 服务解决了我的问题。哈哈有时我们会错过非常基本的东西

标签: asp.net web-services


【解决方案1】:

将 SSL 绑定应用于 Web 服务解决了我的问题。哈哈,有时候我们会错过一些非常基本的东西——

【讨论】:

    最近更新 更多