【问题标题】:Mail Sending problem邮件发送问题
【发布时间】:2011-03-04 15:44:59
【问题描述】:

我已使用此代码发送邮件,但没有收到任何错误,但我能够接收邮件。默认 smtp 服务器也设置为“127.0.0.1”作为“inetmgr”中中继邮件中的本地主机,但我仍然无法接收邮件。不知道问题出在哪里。

emailsender.cs 类中,这是代码:

public void SendEmail(string To, String Subject, String Body, String uname)
{
    string body = "Hi " + uname + ",\n\n \t" + Body + "\n" + " \n Regards, \n LMS Team" + "\n\n\tSent at: " + DateTime.Now + " \n\n\t\t---- This is an auto generated mail. Please do not reply.";
    try
    {
        try
        {
            MailMessage Message = new MailMessage();
            Message.From = new MailAddress("karhik.varadarajan@asteor.com");

            if (!string.IsNullOrEmpty(To))
                Message.To.Add(new MailAddress(To));
            Message.Subject = Subject;
            Message.Body = body;
            try
            {
                SmtpClient smtpClient = new SmtpClient("localhost");
                smtpClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
                smtpClient.Port = 25;
                smtpClient.UseDefaultCredentials = false;
                smtpClient.Send(Message);
            }
            catch (System.Web.HttpException ehttp)
            {
                throw new Exception("Email Sending Failed", ehttp);
            }
        }
        catch (IndexOutOfRangeException ex)
        {
            throw new IndexOutOfRangeException("Email Sending Failed", ex);
        }
    }
    catch (System.Exception ex)
    {
        throw new Exception("Email Sending Failed", ex);
    }
}

.aspx 文件中:

protected void Page_Load(object sender, EventArgs e)
{
    EmailSender email = new EmailSender();
    email.SendEmail("karhik.varadarajan@asteor.com", "testingmail", "this is a test mail", "From");
}

【问题讨论】:

  • 我没有收到任何错误,但我无法接收邮件

标签: c# email


【解决方案1】:

如果您使用 PickupDirectoryFromIis 选项,请检查您的 C:\Inetpub\mailroot\Pickup 或 Queue 或 Badmail 目录是否创建了 EML 文件。如果它在 PickUp 或 Queue 文件夹中,IIS 可能会处理该文件。如果在 BadMail 中,IIS 无法处理该文件。

【讨论】:

  • 如果在第一次试用中无法将电子邮件发送到指定的电子邮件地址,IIS SMTP 服务会将其移动到“队列”文件夹,并且 IIS SMTP 服务将继续重试直到过期。您可以在“控制面板->管理工具->控制面板->管理工具->Internet信息服务->默认SMTP虚拟服务器->属性->传递”中设置IIS SMTP服务的过期超时时间-emailarchitect.net/webapp/smtpcom/developers/smtpservice.asp
【解决方案2】:

我遇到了同样的问题,有时组织不允许访问发送电子邮件。所以我尝试了电子邮件中继服务器。试试弹性电子邮件。

【讨论】:

  • 是的,我在中继邮件选项的默认 smtp 服务器中使用了本地主机,对吧?
【解决方案3】:

如果没有错误,则很可能是 smpt 服务器设置问题。首先,您使用的是 localhost,而不是 127.0.0.1。我建议在调用 localhost 时使用 127.0.0.1 作为最佳实践。

即使它是“不应该太需要”,也没有任何理由,使用 localhost。至少将“127.0.0.1 localhost”放在 windows etc\hosts 文件中。您也可以尝试使用您知道可以访问的外部 SMTP 主机(例如您的 isp)。我知道配置错误的 smtp 主机会在成功发送时出现。

但是,正如上面已经提到的其他问题,可能存在许多其他问题,例如访问发送邮件。不过,我认为大多数类似的错误都会向您抛出错误。

【讨论】:

    猜你喜欢
    • 2011-09-07
    • 2017-06-05
    • 2011-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-05
    • 2012-12-08
    相关资源
    最近更新 更多