2013-01-16 70 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拾取並填充到文件夾中。