ASP.NET - How to send HTML in Mail Body

Asked By Esmail
03-Feb-12 09:11 AM
I have multiple events in ListVIew from where I am extracting Adress, Date and Time as per user selection.
Now i have to send all the details in Mail with all HTML.

My problem is I have created a string for it in which I am giving all HTMLs attributes but I am not able to see the effect.

Please Help/
  D Company replied to Esmail
03-Feb-12 10:02 AM
Hello Friend.

Suppose you got all the necessary information from the list as you have mentioned, and now you want to send them as in HTML format.

you must have declered a object of message class.

MailMessage mymsgfromlists= new MailMessage();

now yoou have to se IsHTML property to true.
mymsgfromlists.IsBodyHtml = true;

than in the format just use <html>tag, will surely help you.

mymsgfromlists.Body = string.Format("<html><head></head><body>and here is your msg</body>");


Hope this will help you!!
Regards
D
  dipa ahuja replied to Esmail
03-Feb-12 11:10 AM
System.Text.StringBuilder s = new System.Text.StringBuilder();
s.Append("<html><body>Enter your name<input type='text'/>");
s.Append("</body></html>");


string subject = "testing mail";

MailMessage msg = new MailMessage();
msg.Body = s.ToString();
  [)ia6l0 iii replied to Esmail
03-Feb-12 12:41 PM
Your html might not be valid, and could be broken. And note that you need to set the IsBodyHtml property of the MailMessage class to true. 

If this does not solve, paste your code blocks where you set the html attributes. 
  kalpana aparnathi replied to Esmail
03-Feb-12 12:42 PM
'(1) Create the MailMessage instance

Dim mm As New MailMessage(FromEmailAddress, ToEmailAddress)

'(2) Assign the MailMessage's properties

mm.Subject = "HTML-Formatted Email Demo Using the IsBodyHtml Property"
mm.Body = "<h2>This is an HTML-Formatted Email Send Using the <code>IsBodyHtml</code> Property</h2><p>Isn't HTML <em>neat</em>?</p><p>You can make all sorts of <span style=""color:red;font-weight:bold;"">pretty colors!!</span>.</p>"

mm.IsBodyHtml = True



'(3) Create the SmtpClient object

Dim smtp As New SmtpClient

'(4) Send the MailMessage (will use the Web.config settings)

smtp.Send(mm)
Create New Account
help
const string fromPassword = "fromPassword"; const string subject = "Subject"; const string body = "Body"; var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(fromAddress.Address, fromPassword) }; using (var message = new MailMessage(fromAddress, toAddress) { Subject = subject, Body = body }) { smtp.Send(message); } Hope this will help you :-) Here System.Net.NetworkCredential _Credential = new System.Net.NetworkCredential(txtusername.Text , txtpassword.Text ); System.Net.Mail.MailMessage _MailMessage = new MailMessage(); _MailMessage.To.Add(txtto.Text); _MailMessage.Subject = txtsubject.Text; _MailMessage.From = new System.Net.Mail.MailAddress(txtusername.Text); _MailMessage.Body = txtbody.Text; System.Net.Mail.SmtpClient _SmtpClient = new System.Net.Mail SmtpClient("smtp.gmail.com"); _SmtpClient.UseDefaultCredentials = false; _SmtpClient.EnableSsl = true; _SmtpClient.Credentials = _Credential; _SmtpClient.Port = 587 code. . . using System.Net.Mail; using System.Net; namespace ConAppNetMail { classProgram { staticvoid Main( string [] args) { MailMessage newMessage = newMailMessage(); SmtpClient mailService = newSmtpClient(); / / set the addresses newMessage.From = newMailAddress(“abc@gmail.com”); newMessage.To.Add(“xyz
string UserName = "" ; / / Ur Gmail address string PassWord = "" ; / / Gmail password NetworkCredential loginInfo = new NetworkCredential (UserName, PassWord); MailMessage msg = new MailMessage (); msg.From = new MailAddress (UserName); msg.To.Add( new MailAddress (to.ToString())); msg.Subject = "Testing Mail" ; msg.Body = textBox1.Text.ToString(); msg.IsBodyHtml = true ; SmtpClient client = new SmtpClient ( "smtp.gmail.com" ); client.EnableSsl = true ; client.UseDefaultCredentials = false ; client.Credentials = loginInfo; client.Send(msg Text; string GmailId = txtUname.Text; string password = txtPassword.Text; string bodyMsg = "helo its testing mail" ; MailMessage mail = new MailMessage (); mail.To.Add(toEmailAddress); mail.From = new MailAddress (GmailId); mail.Subject = txtSubjet.Text; mail.Body l and put the file in memory stream mail.Attachments.Add( new Attachment (fl.FileName)); SmtpClient smtp = new SmtpClient ( "smtp.gmail.com" ); smtp.EnableSsl = true ; smtp.UseDefaultCredentials = false ; smtp.Credentials = new System.Net. NetworkCredential
mail give me full explation with code how to send email in Asp.net hi gupta, this is mail foramt. please check. private void SendMail() { try { SmtpClient smtpClient = new SmtpClient (); MailMessage message = new MailMessage (); StringBuilder sb = new StringBuilder (); message.From = new MailAddress (Session[ "EmailId" ].ToString()); sb.Append( "Hi " + empName[5
Gmail account login through asp.net page C# .NET Hi Friends, I have created a login page for my site. Now want to send email using your Gmail account or using Gmail's smtp server in ASP.NET application or if you don't have a working smtp server to send mails using your ASP.NET application or aspx page than sending e-mail using Gmail is best option. you need code in click event of button C# code protected void Button1_Click( object sender, EventArgs e) { MailMessage mail = new MailMessage(); mail.To.Add( "jainamit.agra@gmail.com" ); mail.To.Add( "amit_jain_online@yahoo.com" ); mail.From
using System.Net.Mail; using CaptchaDLL; using System.Text.RegularExpressions; using System.Text; public partial class Default2 : System.Web.UI.Page { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[ "SaleSelfConnectionString" ].ConnectionString); protected void saleself.com / Activation.aspx?key = " +s+ "&UN = " +txtEmail.Text; AlternateView View = null ; LinkedResource resource = null ; SmtpClient client = null ; StringBuilder msgText = new StringBuilder(); / / msgText.Append("<table width = '100%' cellpadding = '0' cellspacing = '0' > <tr> <td width = '150'> <img src Helvetica, sans-serif; font-size: 12px; color: #333333; padding-left: 10px'> < / p> < / td> < / tr> < / table> " ; MailMessage msg = new MailMessage( "Info@saleself.com" , txtEmail.Text); msg.Subject = "Welcome to SaleSelf.com" ; msg.From = new MailAddress MapPath( "images / saleself.gif" ))); resource.ContentId = "Image1" ; View.LinkedResources.Add(resource); msg.AlternateViews.Add(View); SmtpClient smtpClient = new SmtpClient(); smtpClient.Host = "mail.saleself.com" ; smtpClient.Credentials = new System.Net.NetworkCredential( "Info@SaleSelf