从ASP.NET发送邮件

时间:2010-09-21 11:27:07

标签: 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.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> 

5 个答案:

答案 0 :(得分:1)

我认为您的案例中的问题可能与web.config中的deliveryMethod属性有关;您可能需要与主机进行验证,但该方法将静默地转发Web服务器上的电子邮件文件,期望邮件传输代理提取文件并在以后发送。可能根本没有使用网络元素,因为我认为你有PickupDirectoryFromIis值。

答案 1 :(得分:1)

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

How to test asp.net email is being sent

<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>

答案 2 :(得分:0)

您的投放方式当然应该是网络吗?

http://msdn.microsoft.com/en-us/library/system.net.mail.smtpdeliverymethod.aspx

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

答案 3 :(得分:0)

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

答案 4 :(得分:0)

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

我们设置了PickupDirectoryFromIis,这意味着本地SMTP服务器将启动这些服务器并将中继发送到另一个SMTP。

相关问题