Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.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
上载的ASP.NET web应用程序不发送电子邮件_Asp.net_Email - Fatal编程技术网

上载的ASP.NET web应用程序不发送电子邮件

上载的ASP.NET web应用程序不发送电子邮件,asp.net,email,Asp.net,Email,我正在开发一个web应用程序,计划向新成员发送确认电子邮件。我是ASPET电子邮件服务开发新手。该应用程序运行时没有错误或异常,并且在try-and-catch块返回异常时发送电子邮件。然而,甚至没有人收到一封邮件。代码如下: using System; using System.Net; using System.Web; using System.Net.Mail; using System.Collections.Generic; using System.ComponentModel.C

我正在开发一个web应用程序,计划向新成员发送确认电子邮件。我是ASPET电子邮件服务开发新手。该应用程序运行时没有错误或异常,并且在try-and-catch块返回异常时发送电子邮件。然而,甚至没有人收到一封邮件。代码如下:

using System;
using System.Net;
using System.Web;
using System.Net.Mail;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Text.RegularExpressions;

public void SendEmailAddressVerificationEmail(string Username, string To)
    {
        MEFManager.Compose(this);
        string encryptedName = Username.Encrypt("verify");

        string msg = "Please click on the link below or paste it into a browser to verify your email account.<BR><BR>" +
                        "<a href=\"" + _configuration.RootURL + "Account/VerifyEmail.aspx?a=" +
                        encryptedName + "\">" +
                        _configuration.RootURL + "Account/VerifyEmail.aspx?a=" +
                        encryptedName + "</a>";

        SendEmail(To, "", "", "Account created! Email verification required.", msg);
    }


public void SendEmail(string To, string CC, string BCC, string Subject, string Message)
    {
        MailMessage mm = new MailMessage(FROM_EMAIL_ADDRESS,To);
        if(!string.IsNullOrEmpty(CC))
            mm.CC.Add(CC);

        if (!string.IsNullOrEmpty(BCC))
            mm.Bcc.Add(BCC);

        mm.Subject = Subject;
        mm.Body = Message;
        mm.IsBodyHtml = true;

        Send(mm);
    }


private void Send(MailMessage Message)
    {
        try
        {
        //During developement we will not be sending mails
#if !DEBUG
        SmtpClient smtp = new SmtpClient();
        smtp.Send(Message);
        Console.Write("E-mail sent!");
#endif

        }
        catch(Exception ex)
        {
            Console.Write("Could not send the e-mail - error: " + ex.Message);
        }
    }
此外,web.config和web.release.config文件如下所示:

Web.config:

<system.net>
 <mailSettings>
  <smtp>
            <network host="localhost" port="25" defaultCredentials="true"/>
  </smtp>
 </mailSettings>
</system.net>
web.release.config:

<smtp from="postmaster@itok.com">
  <network
      host="mail.itok.com"  
      defaultCredentials="true"
      enableSsl="false"             
      port="25"
      userName="postmaster@itok.com"
      password="*********"
      xdt:Transform="Replace"
    />
</smtp>

有人能帮我找到原因吗?有没有人有想法或建议去哪里寻找答案?这种问题的根源是什么

我无法回答你的问题,但这里有一些提示太长,无法在评论中发表

在您的开发环境中,启用使用交付方法指定的ICKUPdirectory发送邮件,而不是使用条件编译禁用发送邮件(如果有!)!调试

这将使您能够在开发环境中测试代码-只需检查电子邮件文件是否在指定的目录中创建,该目录必须存在并且可由web应用程序写入

<smtp deliveryMethod="SpecifiedPickupDirectory" from="postmaster@itok.com">
  <network host="localhost"/>
  <specifiedPickupDirectory pickupDirectoryLocation="C:\Temp\mails\"/>
</smtp>
如果它在您的开发环境中工作,那么您可以假设您的代码可能是正常的,问题在于部署的配置


您在web应用程序中使用Console.Write-to-log错误看起来可疑:您希望在哪里看到这些错误

嗨,乔,非常感谢你的回复。我已经应用了更改,现在我可以在C:\Temp\mails\目录中找到电子邮件。因此,现在我确信我的代码在生成链接电子邮件时可以完美地工作。你知道从这里到哪里去寻找问题的解决方案吗?我给ISP打过电话,他们认为配置就是他们已经给我的配置@下一步我要尝试的是移除try/catch块。如果您的配置有问题,我希望抛出异常,但我不知道Console.Write如何帮助您查看异常详细信息。我的问题就在这里。代码要么不抛出任何异常,要么抛出但我检测不到它。但很明显,一切似乎都很好。它给出的信息是:邮件已发送!!!还有控制台。写是我的错。我在测试一些东西,但我忘了把它取下来。