好的,所以我有这个程序,它实质上是公司的电子邮件客户端,它为他们构造电子邮件并将其发送出去。
我已经完成了所有工作,但是在发送电子邮件时,他们会收到 Mailbox Unavailable. Accessed Denied - Invalid HELO Name
不过,有趣的是,我为网络凭据和from部分使用了相同的用户名。
编辑:更新代码到我现在正在使用...现在得到Failure sending mail
错误。
这是我的MailConst.cs
课:
public class MailConst
{
/*
*/
public static string Username = "username";
public static string Password = "password";
public const string SmtpServer = "smtp.domain.co.uk";
public static string From = Username + "@domain.co.uk";
}
这是我的主类中这些变量的用法:
public static void SendMail(string recipient, string subject, string body, string[] attachments)
{
SmtpClient smtpClient = new SmtpClient();
NetworkCredential basicCredential = new NetworkCredential(MailConst.Username, MailConst.Password, MailConst.SmtpServer);
MailMessage message = new MailMessage();
MailAddress fromAddress = new MailAddress(MailConst.From);
// setup up the host, increase the timeout to 5 minutes
smtpClient.Host = MailConst.SmtpServer;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = basicCredential;
smtpClient.Timeout = (60 * 5 * 1000);
message.From = fromAddress;
message.Subject = subject + " - " + DateTime.Now.Date.ToString().Split(' ')[0];
message.IsBodyHtml = true;
message.Body = body.Replace("\r\n", "<br>");
message.To.Add(recipient);
if (attachments != null)
{
foreach (string attachment in attachments)
{
message.Attachments.Add(new Attachment(attachment));
}
}
smtpClient.Send(message);
}
只是作为旁注。该程序在使用我的凭据时有效,在通过我自己的服务器时,将其链接到它们的凭据时不起作用。
为了解决这个问题,我不得不使用可选参数Domain
为NetworkCredential
我的代码现在看起来像这样:
NetworkCredential basicCredential = new NetworkCredential(MailConst.UserName, MailConst.Password, MailConst.Domain
其中MailConst.Domain
是指向Exchange域的字符串。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句