0

我正在尝试发送邮件,在本例中为 gridview 到我机器上的指定文件夹,以便能够查看邮件。因此,我正在发送邮件,但它并没有最终出现在文件夹中。我怎样才能做到这一点?

我将此添加到 web.config:

<system.net>
<mailSettings >
  <smtp deliveryMethod="Network" from="ArianG@lr.co.za">
    <network host="staging.itmaniax.co.za"/>
    <specifiedPickupDirectory pickupDirectoryLocation="C:\testdump\emaildump\"/>
  </smtp>
</mailSettings>

这是我发送 gridview 的代码。(我认为我不需要 SmtpClient,因为我不想连接到端口,25 或 587):

private void MailReport()
{
    //*****************************************************
    string to = "arianul@gmail.com";
    string From = "ArianG@lr.co.za";
    string subject = "Report";
    string Body = "Good morning, Please view attachment<br> Plz Check d Attachment <br><br>";

    Body += GridViewToHtml(GridView1);

    Body += "<br><br>Regards,<br>Arian Geryts(ITManiax)";
    bool send = sendMail(to, From, subject, Body);

    if (send == true)
    {
        string CloseWindow = "alert('Mail Sent Successfully!');";
        ClientScript.RegisterStartupScript(this.GetType(), "CloseWindow", CloseWindow, true);
    }
    else
    {
        string CloseWindow = "alert('Problem in Sending mail...try later!');";
        ClientScript.RegisterStartupScript(this.GetType(), "CloseWindow", CloseWindow, true);
     }
    //*****************************************************

}

public bool sendMail(string to, string from, string subject, string body)
{
    bool k = false;
    try
    {
        MailMessage msg = new MailMessage(from, to);
        msg.Subject = subject;

        AlternateView view;
        SmtpClient client;
        StringBuilder msgText = new StringBuilder();
        view = AlternateView.CreateAlternateViewFromString(msgText.ToString(), null, "text/html");
        msg.AlternateViews.Add(view);
        msgText.Append(" <html><body><br></body></html> <br><br><br>  " + body);

        //*****
        /*client = new SmtpClient("smtp.gmail.com", 25);
        client.Host = "staging.itmaniax.co.za";
        client.Port = 25;

        //****
        client.EnableSsl = true;
        client.Send(msg);*/

        k = true;     
    }
4

1 回答 1

1

将 web.config 中的邮件设置更改为:

  <smtp deliveryMethod="SpecifiedPickupDirectory">
    <specifiedPickupDirectory pickupDirectoryLocation="C:\smtp" />

这应该可以解决问题。或者,您可以在部署解决方案后通过 IIS gui 更改设置。

亲切的问候。

/edit:当然你需要一个 smtp 客户端。该程序必须将电子邮件消息发送到 smtp 服务器。该消息只是被 IIS 拾取并填充到一个文件夹中。

于 2013-01-16T10:16:54.973 回答