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. .
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Pankaj PandeyRank #642 · 3.7K reputationPosted Jun 21, 2013, 12:35 AM EDT
where you getting problem..in reading file or sending the mail?
Sunny SharmaRank #223 · 11.1K reputationPosted Jun 21, 2013, 1:32 AM EDT
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!