我正在尝试发送邮件,在本例中为 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;
}