I am trying to send a mail, in this case a gridview to a specified folder on my machine as to be able to view the message. I am thus sending the mail but it is not ending up in the folder. How can I do this?
I added this to 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>
This is my code for sending the gridview. (I presume I do not need SmtpClient as I do not want to connect to a port, either 25 or 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;
}
Change your mail Setting in web.config to:
This should do the trick. Alternativly you could change the setting via tha IIS gui, after you deployed the solution.
Kind regards.
/edit: of course you need a smtp client. The program has to fire the email message out to the smtp server. The message just gets picked up by IIS and stuffed into a folder.