我正在构建一个需要从客户端计算机发送电子邮件的应用程序
public static void sendMailLocal(string mailSubject, string userMail, string mailBody)
{
try
{
string cliantMail = userMail;
string subject = mailSubject;
string body = string.Format("user email:{0}\n{1}",cliantMail,mailBody);
string email;
string password;
string host;
email = getMailAddrese();
password = getPassword();
host = getHostName();
var fromAddress = new MailAddress(email, "From Name",ncoding.Unicode);
var toAddress = new MailAddress(email, "To Name");
string fromPassword = password;
SmtpClient smtp = new SmtpClient
{
Host = host,
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new tworkCredential(fromAddress.Address,fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}
}
catch (Exception ex)
{
}
}
现在此代码适用于某些计算机并在其他计算机上崩溃。经过一番调查,我发现如果他们的名字是英文的,它可以正常工作,但如果计算机名称是希伯来语,它就会崩溃。
那么有没有人知道我可以发送邮件而不管计算机名称的方式?
我得到的错误是 system.net.mail.smtpexception 发送邮件失败 system.formatexception
我在 smtp.send(message) 上得到它;