我创建了一个Web服务(Windows Server 2018 R2 Enterprise),我在其中使用代码发送邮件
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”之类的地址。.有人可以帮助我吗
答案 0 :(得分:0)
将SSL绑定应用于Web服务解决了我的问题。哈哈有时候我们会错过一些非常基本的东西–