Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从ASP.NET发送邮件_C#_Asp.net_Email - Fatal编程技术网

C# 从ASP.NET发送邮件

C# 从ASP.NET发送邮件,c#,asp.net,email,C#,Asp.net,Email,我在通过代码发送邮件时遇到问题。实际上,代码运行良好,没有错误,但邮件没有到达我发送的用户。我正在将代码粘贴到下面。请检查一下并告诉我问题所在 System.Net.Mail.MailMessage msgMail = new System.Net.Mail.MailMessage(); msgMail.From = new System.Net.Mail.MailAddress("veerab@orbees.com"); msgMail.To.Add(new System.Net.Mail.

我在通过代码发送邮件时遇到问题。实际上,代码运行良好,没有错误,但邮件没有到达我发送的用户。我正在将代码粘贴到下面。请检查一下并告诉我问题所在

System.Net.Mail.MailMessage msgMail = new System.Net.Mail.MailMessage(); 
msgMail.From = new System.Net.Mail.MailAddress("veerab@orbees.com");
msgMail.To.Add(new System.Net.Mail.MailAddress("abhi.orbees@gmail.com"));
string currentuseremail = web.CurrentUser.Email.ToString();
msgMail.Subject = "Request:Joing into the  myitem.Title.ToString()";
msgMail.IsBodyHtml = true;
string strBody = "test mail";
msgMail.Body = strBody;
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
client.Send(msgMail);  
我将web.config配置为:

<system.net>
    <mailSettings>
        <smtp deliveryMethod="PickupDirectoryFromIis">
            <network host="smtpout.secureserver.net" port="25" defaultCredentials="true"/>
        </smtp>
    </mailSettings>
    <settings>
        <httpWebRequest useUnsafeHeaderParsing="true"/>
    </settings>
</system.net> 


我认为您的问题可能是web.config中的deliveryMethod属性;您可能需要与主机进行验证,但该方法将在web服务器上以静默方式转储电子邮件文件,希望邮件传输代理拾取文件并稍后发送。网元可能根本没有被使用,因为我认为您具有PickupDirectoryFromIis值。

您的传递方法肯定应该是网络


否则,您需要在本地计算机上安装IIS/SMTP才能发送邮件,IIRC。

检查您的本地SMTP服务器是否正在运行。因为您的
DeliveryMethod
是PickupDirectoryFromIis,邮件将被写入本地分拣目录,由SMTP服务器(它是IIS的一部分)发送。

我认为运行IIS的计算机上的SMTP配置不正确,或者根本没有运行。您可能可以在Inetpub子文件夹中看到您发送的电子邮件


如果您从IIS设置PickupDirectoryFromIis,这意味着本地SMTP服务器将拾取这些内容,并将其中继到另一个SMTP。

首先设置本地目录以接收您的邮件。这将排除任何代码问题,然后再进一步排除故障:



你试过把它放在Try-Catch块中吗?是的。我把整个代码放在Try-Catch块中。在调试过程中,它不会显示任何主题和主体的异常,这可能会被谷歌的反垃圾邮件引擎“吃掉”。尝试传送到其他(非GMail)帐户。使用System.Net.Mail整理您的代码;如何与我的主机验证deliveryMethod属性?我的本地smtp服务器正在运行。IIS/smtp已安装在我的服务器中,并且它们正在运行。当我将deliveryMethod属性更改为deliveryMethod='SpecifiedPickupDirectory'时,当我将web.config更改为上述指定目录时,我将邮件发送到该目录,然后邮件会被放到那个文件夹里。好吧,我们知道这不是你的代码。我已经更新了我的答案。将您的配置更改为类似以下内容,并确认主机上的正确设置。。。确保注释掉投递文件夹的第一封邮件设置:-)
<mailSettings>
    <smtp deliveryMethod='SpecifiedPickupDirectory'>
        <specifiedPickupDirectory pickupDirectoryLocation="c:\maildrop" />
    </smtp>
</mailSettings>

<mailSettings>
    <smtp from="me@mysite.com">
        <network host="xx.xx.xxx.xx" port="25" defaultCredentials="true"/>
    </smtp>
</mailSettings>