我正在尝试向我的计算机上的指定文件夹发送邮件,在这种情况下是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;
}
答案 0 :(得分:1)
将web.config中的邮件设置更改为:
<smtp deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="C:\smtp" />
这应该可以解决问题。另外,在部署解决方案之后,您可以通过IIS gui更改设置。
亲切的问候。
/ edit:当然你需要一个smtp客户端。程序必须将电子邮件消息发送到smtp服务器。该消息刚刚被IIS拾取并填充到文件夹中。