简体   繁体   English

在C#中使用localhaost的Sendmail时收到错误消息“发送邮件失败”

[英]Getting Error message “failure sending mail ” while Sendmail using localhaost in C#

I'm trying to send mail from machine(Windows 7), which doesn't have IIS server and mail server but this machine is connected to LAN. 我正在尝试从机器(Windows 7)发送邮件,该机器没有IIS服务器和邮件服务器,但该机器已连接到LAN。 Do we really need IIS server to send mail with localhost. 我们是否真的需要IIS服务器通过localhost发送邮件。 Please help me to understand the concept of localhost, What are the pre-conditions are required to use "localhost" as SMTP server. 请帮助我了解localhost的概念,使用“ localhost”作为SMTP服务器需要哪些先决条件。 I tried with Gmail SMTP host, it was working fine without any issues. 我尝试使用Gmail SMTP主机,但工作正常,没有任何问题。

Here is my Code : 这是我的代码:

SmtpClient client = new SmtpClient();               
client.Host = "localhost";                
client.Port = 25;
client.EnableSsl = true;
client.Credentials = new System.Net.NetworkCredential("Admin", "password");
client.UseDefaultCredentials = false;              
try
{
client.Send(mail);
}
catch (Exception ex)
{
logger.LogInfo(ex.Message); 
}

Thanks, Delwin 谢谢,德尔文

You will need to use IIS/ mail server / something for sending from your local machine. 您将需要使用IIS /邮件服务器/从本地计算机发送邮件。

If you are just trying to test, then you can use this to help simulate it: 如果您只是想测试,那么可以使用它来模拟它:

http://antix.co.uk/Projects/SMTP-Server-For-Developers http://antix.co.uk/Projects/SMTP-Server-For-Developers

You can install Smtp4Dev if you want just to do some testing during development. 如果您只想在开发过程中进行一些测试,则可以安装Smtp4Dev

If I remember well SMTP was stripped from the latest versions of IIS, so you'll need to find another tool anyway. 如果我还记得SMTP已从IIS的最新版本中删除,那么无论如何您都需要找到其他工具。

To send an email you need an SMTP server program. 要发送电子邮件,您需要SMTP服务器程序。 You either have one locally (ie "localhost", and handily for you there is one built into IIS), or you connect to a remote server. 您可以在本地拥有一个(即“ localhost”,并且方便地在IIS中内置一个),也可以连接到远程服务器。

If you don't like the idea of IIS I'm sure there are other SMTP servers you could use, but you'll need something if you wish to send locally. 如果您不喜欢IIS的想法,那么我确定您可以使用其他SMTP服务器,但是如果您希望在本地发送,则需要一些东西。

You don't need smtp server, you can store mails in filesystem, set your development web.config like this : 您不需要smtp服务器,可以将邮件存储在文件系统中,如下设置开发web.config:

<system.net>
  <mailSettings>
    <smtp deliveryMethod="SpecifiedPickupDirectory">
      <specifiedPickupDirectory
            pickupDirectoryLocation="w:\razvoj\TestAndBuild\UnitTestMailSend" />
    </smtp>
  </mailSettings>
</system.net>

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

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