2013-01-16 32 views
0

我想发送一个邮件,在这种情况下,一个gridview到我的机器上的指定文件夹,以便能够查看邮件。因此,我发送邮件,但它并没有在文件夹中结束。我怎样才能做到这一点?通过网络发送邮件到文件夹

我将此添加到web.config中:

<system.net> 
<mailSettings > 
    <smtp deliveryMethod="Network" from="[email protected]"> 
    <network host="staging.itmaniax.co.za"/> 
    <specifiedPickupDirectory pickupDirectoryLocation="C:\testdump\emaildump\"/> 
    </smtp> 
</mailSettings> 

这是我送的gridview的代码。 (我相信我不需要SmtpClient,因为我不想要连接到一个端口,25或587):在web.config中

private void MailReport() 
{ 
    //***************************************************** 
    string to = "[email protected]"; 
    string From = "[email protected]"; 
    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;  
    } 

回答

1

更改您的邮件设置到:

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

这应该做的伎俩。或者,您可以在部署解决方案后,通过thai IIS gui更改设置。

亲切的问候。

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