简体   繁体   English

从 Windows 服务发送电子邮件:事务失败。 服务器响应为 5.7.1 客户端主机拒绝访问被拒绝

[英]Send Email from Windows Service: Transaction failed. the server response was 5.7.1 client host rejected access denied

The below code is working fine from Windows Form, but not working from Windows Services.下面的代码在 Windows 窗体中运行良好,但在 Windows 服务中无法运行。 The service is running on Windows XP.该服务在 Windows XP 上运行。

I have tried changing the log on user, but did not work.我试过更改登录用户,但没有奏效。

Error: Transaction failed.错误:交易失败。 the server response was 5.7.1 client host rejected access denied服务器响应为 5.7.1 客户端主机拒绝访问被拒绝

private void SendEmailToHO()
{
    try
    {
        int mailSentSuccessfully = 0;

        MailAddress to = new MailAddress(mailTo);
        MailAddress from = new MailAddress(mailFrom);

        using (MailMessage mail = new MailMessage(from.Address, to.Address))
        {

            int attachmentCount = 0;

            try
            {
                foreach (string fileName in fileEntries)
                {
                    Attachment attachment = new Attachment(fileName);
                    mail.Attachments.Add(attachment);
                    attachmentCount++;
                }

                SmtpClient client = new SmtpClient(mailHost, port);
                if (enableSSL == "Y")
                {
                    client.EnableSsl = true;
                }
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                client.UseDefaultCredentials = false;
                client.Credentials = new System.Net.NetworkCredential(mailUser, mailPassword);

                mail.Subject = "Email Subject " + clientID;
                mail.Body = "Attached please find the files: " + clientIDTitle;

                if (attachmentCount > 0)
                {
                    //
                    client.Send(mail);

                    //if no error, this code will work.
                    mailSentSuccessfully = 1;

                    new MyApp.LogWriter("Sent mail to " + to.Address + ", \nAttachment count = " + attachmentCount);
                }
                else
                {
                    new MyApp.LogWriter("Attachment count = " + attachmentCount);
                }
            }
            catch (Exception ex)
            {
                new MyApp.LogWriter("Send mail failed. Cause: " + ex.Message
                                          + "\n Inner Exception: " + ex.InnerException);
            }
        }
    }
    catch (System.Exception ex)
    {
        new BTCClient.LogWriter("Email Error '" +
                           ex.Message + "'");
    }
}

我遇到了同样的问题,要解决此问题,您需要联系您的电子邮件服务器的服务提供商,并告诉他们授予您服务器 IP 的访问权限。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 交易失败。 服务器响应为:5.7.1伪造的HELO - Transaction failed. The server response was: 5.7.1 Forged HELO 交易失败。 服务器响应为:SMTP 主机 - Transaction failed. The server response was: SMTP Host 服务器响应为:5.7.1使用SMTP客户端发送电子邮件时未对客户端进行身份验证 - The server response was: 5.7.1 Client was not authenticated While Sending email using SMTP client 中继访问被拒绝 5.7.1 - Relay access denied 5.7.1 信箱不可用。 服务器响应为:5.7.1客户端无权发送此发送者 - Mailbox unavailable. The server response was: 5.7.1 Client does not have permissions to send as this sender 服务器拒绝了客户端凭据,WCF 作为 Windows 服务 - The server has rejected the client credentials, WCF as Windows Service 邮箱名称不允许。 服务器响应为:5.7.1 <sender@abcd.com> :发件人地址被拒绝:未登录 - Mailbox name not allowed. The Server response was: 5.7.1 <sender@abcd.com>:Sender address rejected:not logged in 如何从 Windows 服务发送电子邮件? - How to send email from a Windows service? 正在发送电子邮件错误:邮箱不可用。 客户端主机被拒绝 - Sending email error: Mailbox unavailable. Client host rejected Kube.netes 客户端 C#:无法拉取图像:rpc 错误:代码 = Unknown desc = 来自守护程序的错误响应:拉取访问被拒绝 - Kubernetes client C#: Failed to pull image: rpc error: code = Unknown desc = Error response from daemon: pull access denied for
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM