通过Microsoft Exchange Server发送电子邮件

扎克·罗斯·克莱恩(Zach Ross-Clyne)

好的,所以我有这个程序,它实质上是公司的电子邮件客户端,它为他们构造电子邮件并将其发送出去。

我已经完成了所有工作,但是在发送电子邮件时,他们会收到 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);
    }

只是作为旁注。该程序在使用我的凭据时有效,在通过我自己的服务器时,将其链接到它们的凭据时不起作用。

扎克·罗斯·克莱恩(Zach Ross-Clyne)

为了解决这个问题,我不得不使用可选参数DomainNetworkCredential

我的代码现在看起来像这样:

NetworkCredential basicCredential = new NetworkCredential(MailConst.UserName, MailConst.Password, MailConst.Domain

其中MailConst.Domain是指向Exchange域的字符串。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

通过Exchange Web服务(EWS)发送电子邮件

来自分类Dev

如何通过MS Exchange Server用emacs发送电子邮件

来自分类Dev

如何使用Microsoft Exchange发送电子邮件附件?

来自分类Dev

Microsoft.Exchange.WebServices.Data.ServiceResponseException:发送电子邮件时

来自分类Dev

通过 Exchange WebService API 重新发送电子邮件

来自分类Dev

通过Mandrill发送电子邮件

来自分类Dev

通过gmail发送电子邮件

来自分类Dev

通过PHP发送电子邮件

来自分类Dev

无法通过python发送和发送电子邮件

来自分类Dev

通过 Microsoft Exchange 服务器同步电子邮件标签

来自分类Dev

通过SQL Server发送电子邮件会导致错误

来自分类Dev

无法通过SSL通过SMTP发送电子邮件

来自分类常见问题

无法使用Microsoft.Graph发送电子邮件

来自分类Dev

无法使用Microsoft.Graph发送电子邮件

来自分类Dev

使用Postfix通过Java发送电子邮件

来自分类Dev

尝试使用Python通过GoDaddy发送电子邮件

来自分类Dev

通过gmail和python发送电子邮件

来自分类Dev

通过SmtpClient发送电子邮件会引发异常

来自分类Dev

Java通过gmail发送电子邮件

来自分类Dev

通过mailgun发送电子邮件时出错

来自分类Dev

如何通过Spring发送电子邮件

来自分类Dev

使用Java批注通过Spring发送电子邮件

来自分类Dev

如何通过MIMEMultipart发送电子邮件正文

来自分类Dev

使用Perl通过G Suite发送电子邮件

来自分类Dev

通过VB.net发送电子邮件

来自分类Dev

通过VBA从Excel发送电子邮件附件

来自分类Dev

无法通过openshift发送电子邮件

来自分类Dev

如何通过Mailgun发送电子邮件模板?

来自分类Dev

如何使用python通过gmail发送电子邮件?

Related 相关文章

热门标签

归档