通过 SMTP 从内部电子邮件地址发送电子邮件 - 邮箱不可用或不是本地的 (.NET 4)

发布于 2024-10-14 07:51:11 字数 1409 浏览 4 评论 0原文

我的问题是我无法发送从服务器上托管的收件人发送的 SMTP 电子邮件。我的联系表单适用于以发件人收件人作为外部电子邮件地址的电子邮件,但现在我需要我的系统之一将电子邮件从同一服务器上托管的域发送到任何其他提供的电子邮件(订阅者),它只是给了我错误:

发送电子邮件时出错:邮箱 不可用。服务器响应是: 请求的操作未执行:邮箱 不可用或不在本地

我正在 windows 服务器 上使用 IIS7 运行 ma​​ilEnable,想知道是否有人遇到此问题?我已经通过 Outlook 使用上述详细信息测试了邮箱,它可以正常发送/接收电子邮件。下面是一个代码示例,显示了我正在使用的内容,据我所知,它应该可以很好地进行身份验证。我还尝试将配置设置移回到 C# 代码中,但遇到了同样的问题。

web.config 示例:

<system.net>
    <mailSettings>
        <smtp deliveryMethod="Network" from="[email protected]">
            <network defaultCredentials="true" host="mail.test.com" port="25" userName="[email protected]" password="******" />
        </smtp>
    </mailSettings>
</system.net>

C# .NET 4 代码示例:

try
{
 _emailMsg.Body = _MessageBody;
 _emailMsg.Priority = MailPriority.Normal;

 SmtpClient mSmtpClient = new SmtpClient();

 mSmtpClient.UseDefaultCredentials = true;

 mSmtpClient.Send(_emailMsg);
 return true;
}
catch (Exception ex)
{
 throw new Exception("Error Sending Email: " + ex.Message);

 return false;
}

My problem is that I can't send SMTP emails sent from a recipient hosted on my server. I have contact forms that work fine for emails with a from recipient as an external email address but now I require one of my systems to send emails from a domain hosted on the same server to any other provided email (subscriber) and it just gives me the error:

Error Sending Email: Mailbox
unavailable. The server response was:
Requested action not taken: mailbox
unavailable or not local

I am running mailEnable on a windows server with IIS7 and wondered if anyone was having this problem? I have tested the mailbox using the details above through outlook and it send / receives emails fine. Here is a code sample below showing what I'm using and as far as I know it should be authenticating fine. I also tried moving the config settings back into the C# code and had the same issue.

Example web.config:

<system.net>
    <mailSettings>
        <smtp deliveryMethod="Network" from="[email protected]">
            <network defaultCredentials="true" host="mail.test.com" port="25" userName="[email protected]" password="******" />
        </smtp>
    </mailSettings>
</system.net>

Example C# .NET 4 code:

try
{
 _emailMsg.Body = _MessageBody;
 _emailMsg.Priority = MailPriority.Normal;

 SmtpClient mSmtpClient = new SmtpClient();

 mSmtpClient.UseDefaultCredentials = true;

 mSmtpClient.Send(_emailMsg);
 return true;
}
catch (Exception ex)
{
 throw new Exception("Error Sending Email: " + ex.Message);

 return false;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空名 2024-10-21 07:51:11

查看 MailEnable 的网站,有一些有关错误消息的指南这可能会发生。

进一步猜测,您的域名似乎存在于网络服务器上,并且那里没有问题,但您必须明确地将任何电子邮件地址列入白名单 address-map.tab 文件。关于这个问题还有更多注释,其完整解决方案是:

当您认为不应该返回此错误时,这里的解决方案确实可以解决。如果该地址被认为存在于服务器上,那么您需要检查该事务的 SMTP 日志活动,然后进行调试以查看是否有任何错误描述可以更好地解释该地址发送到时发生的情况。然后您应该检查您的配置以确保该地址确实存在。检查 MailEnable\Config 目录中的 address-map.tab 文件或相关数据库表中是否有包含相关邮箱名称的行也是一个好主意。如果您正在检查发件人无法通过服务器中继的原因,那么您此时应该检查客户端设置并确保客户端中的出站设置已配置为这样,以便它们可以通过服务器中继到非本地电子邮件地址。< /p>

Looking at MailEnable's website, there is some guidance on the error messages that might occur.

Guessing a bit further, it appears that your domain name exists on the web server and there is no issue there, but you have to explicitly white-list any email addresses in the address-map.tab file. There are more notes on the issue and their resolution in full is:

The resolution here really resolves around when you think this error is being returned when it should not be. If the address is thought to exist on the server then you need to check the SMTP logs activity for the transaction and then the debug to see if there are any error descriptions that better explain what happened when the address was sent to. Then you should check your configuration to ensure that the address does exist. It can also be a good idea to check the address-map.tab file in the MailEnable\Config directory or relevant database table for a line that contains the mailbox name in question. If you are checking why the sender could not relay through the server then you should at this time check the client settings and ensure that the outbound settings in the client are configured as such so they can relay through the server to non local email addresses.

唔猫 2024-10-21 07:51:11

使用这个:

try {
    _emailMsg.Body = _MessageBody;
    _emailMsg.Priority = MailPriority.Normal;

     SmtpClient mSmtpClient = new SmtpClient(server,25);
     mSmtpClient.Send(_emailMsg);
     return true;
} catch (Exception ex) { 
     throw new Exception("Error Sending Email: " + ex.Message);
     return false;
}

Use this:

try {
    _emailMsg.Body = _MessageBody;
    _emailMsg.Priority = MailPriority.Normal;

     SmtpClient mSmtpClient = new SmtpClient(server,25);
     mSmtpClient.Send(_emailMsg);
     return true;
} catch (Exception ex) { 
     throw new Exception("Error Sending Email: " + ex.Message);
     return false;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文