MAil Service In C#
I have an HTML file and I want this file read at the code behind and read ans store it to the string For mail Body. .
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sunny SharmaPosted Jun 21, 2013, 5:32 AM
you can read an html file just like a text file. Below is a sample for you on parsing text from HTML file, adding it to the message body and sending the email.
--------------------------------------------------------------------
SmtpClient EmailClient = new SmtpClient("smtp.gmail.com", 587);
EmailClient.Credentials = new NetworkCredential("[email protected]", "pass@123");
EmailClient.EnableSsl = true; TextReader tr = new StreamReader("Test.html");
string messageBody = tr.ReadToEnd();
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.Body = messageBody; msg.IsBodyHtml = true; msg.Subject = "Test Subject";
msg.From = new MailAddress("[email protected]", "Sender Name");
msg.To.Add("[email protected]"); EmailClient.Send(msg);
-----------------------------------------------------------------------
Hope you got the point.
Mark this as answer if it helps.
Cheers!
Pankaj PandeyPosted Jun 21, 2013, 4:35 AM
where you getting problem..in reading file or sending the mail?