System.Net.Mail显示名称失败

时间:2015-04-21 15:19:38

标签: vb.net system.net.mail

我目前正在以下列方式使用System.Net.Mail:

Message.BodyEncoding = Encoding.UTF8
Message.From = New System.Net.Mail.MailAddress(EMail)
Message.IsBodyHtml = True
Message.Subject = theSubject
Message.Body = theBody

Dim client As New System.Net.Mail.SmtpClient()
client.UseDefaultCredentials = False
client.Credentials = New System.Net.NetworkCredential(EMail, EMailPwd)
client.EnableSsl = True
client.Host = "smtp.gmail.com"
client.Port = 587

以这种方式发送它可以正常工作。但是在尝试指定显示名称时:

Message.From = New System.Net.Mail.MailAddress(EMail, firstName & " " & lastName)

我从未收到过该消息,也没有抛出异常。我也尝试过这样格式化:

Message.From = New System.Net.Mail.MailAddress(fullName & " <" & EMail & ">")

是否有理由在没有出现任何错误的情况下仍然失败? Gmail的SMTP服务器是否有限制阻止它?

1 个答案:

答案 0 :(得分:1)

在弄乱之后,我可以通过为from地址指定unicode编码类型来发送它:

Message.From = New System.Net.Mail.MailAddress(EMail, FirstName & " " & LastName, Encoding.Unicode)