通过网络向文件夹发送邮件
本文关键字:文件夹 网络 | 更新日期: 2023-09-27 17:53:27
我正试图发送一封邮件,在这种情况下,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;
}
更改web邮件设置。配置:
<smtp deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="C:'smtp" />
这应该能奏效。或者,您也可以在部署解决方案后通过IIS gui更改设置。
亲切的问候。
/edit:当然你需要一个SMTP客户端。该程序必须将电子邮件发送到smtp服务器。此消息仅被IIS拾取并填充到文件夹中。