简体   繁体   English

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

[英]Getting error while sending email through SMTP

I am getting following error message while sending email through SMTP service: 通过SMTP服务发送电子邮件时出现以下错误消息:

在此处输入图片说明

I have following SMTP setting on my system: 我的系统上有以下SMTP设置:

在此处输入图片说明

Operating system: Windows 7 Home Premium 操作系统:Windows 7 Home Premium

IIS: IIS 7 IIS:IIS 7

How can i resolve this problem? 我该如何解决这个问题?

Thanks. 谢谢。

Based on the inner exception and your code, you're trying to send mail via 127.0.0.1. 根据内部异常和您的代码,您尝试通过127.0.0.1发送邮件。

Removing the line in your code that is setting the smtp host to 127.0.0.1 should cause the site to use the SMTP settings as defined in IIS. 删除将smtp主机设置为127.0.0.1的代码中的行应使站点使用IIS中定义的SMTP设置。

As SMTP settings will usually vary in between server setups, live / test environments, it is usually best to not hard-code SMTP settings such as Host in your code and instead to set the settings via IIS (which actually takes from web.config's section system.net/mailSettings). 由于SMTP设置通常会在服务器设置,实时/测试环境之间变化,因此通常最好不要在代码中硬编码SMTP设置(例如Host),而应通过IIS设置设置(这实际上来自web.config的部分) system.net/mailSettings)。

Edit: 编辑:

As your web.config doesn't have a mailSettings section, I would assume you took the screenshot from the SMTP Email in IIS7 in the server view. 由于您的web.config没有mailSettings部分,因此我假设您从服务器视图中的IIS7中的SMTP电子邮件中截取了屏幕截图。 There's a similar section in the website view. 网站视图中有一个类似的部分。

You can manually add the mailSettings to the web.config: I usually do so. 您可以将mailSettings手动添加到web.config中:通常我这样做。

For your setup (ie, storing emails as file in a directory), the following would be needed: 对于您的设置(即,将电子邮件作为文件存储在目录中),将需要以下内容:

  <system.net>
    <mailSettings>
      <smtp deliveryMethod="specifiedPickupDirectory">
        <specifiedPickupDirectory pickupDirectoryLocation="c:\inetpub" />
      </smtp>
    </mailSettings>
  </system.net>

Note that this wouldn't send emails, but just store them in the folder for a SMTP server to pick them up. 请注意,这不会发送电子邮件,而只是将它们存储在SMTP服务器的文件夹中以进行提取。 To send them, you'll need to setup a SMTP server or connect to a third party one like http://sendgrid.com . 要发送它们,您需要设置SMTP服务器或连接到http://sendgrid.com之类的第三方。

I would suggest you look at the exception detail, including any inner exception. 我建议您查看异常详细信息,包括任何内部异常。 To hazard a guess, maybe you don't have permission to write to C:\\Inetpub. 冒昧地猜测一下,也许您没有写C:\\ Inetpub的权限。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM