Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 28, 2013 06:40 AM by jitendraverma
0 Points
17 Posts
Feb 23, 2013 02:11 PM|LINK
Hi all,
I have problem with presenting data on my email.
Here is my code:
if (IsPostBack) { SmtpClient sc = new SmtpClient("mail.xxxx.com"); System.Text.StringBuilder sb = new System.Text.StringBuilder(); MailMessage msg = new MailMessage(); msg.IsBodyHtml = true;
sb.Append("\n"); sb.Append("PERSONAL DETAILS: \n"); sb.Append("-------------------------------------------------- \n"); sb.Append("<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\">"); sb.AppendFormat("<tr><td>Title:</td><td>{0}</td></tr>", title_1.Text.Trim()); sb.AppendFormat("<tr><td>Family name:</td><td>{0}</td></tr>", surname.Text.Trim()); sb.AppendFormat("<tr><td>Forename:</td><td>{0}</td></tr>", forename.Text.Trim()); sb.AppendFormat("<tr><td>Gender:</td><td>{0}</td></tr>", gender.Text.Trim()); sb.AppendFormat("<tr><td>Date Of Birth:</td><td>{0}</td></tr>", dob.Text.Trim()); sb.AppendFormat("<tr><td>Country:</td><td>{0}</td></tr>", Country.Text.Trim()); sb.AppendFormat("<tr><td>Home Telephone:</td><td>{0}</td></tr>", telephon.Text.Trim()); sb.AppendFormat("<tr><td>Mobile:</td><td>{0}</td></tr>", mobile.Text.Trim()); sb.AppendFormat("<tr><td>E-Mail:</td><td>{0}</td></tr>", email.Text.Trim()); sb.AppendFormat("<tr><td>Fax No:</td><td>{0}</td></tr>", fax.Text.Trim()); sb.Append("</table>"); try { msg = new MailMessage(email.Text, "info@enuktranslation.co.uk", "EDUCATION PLACE REQUEST", sb.ToString()); sc.Send(msg); } catch (Exception ex) { // something bad happened Response.Write("Something bad happened!"); } finally { if (msg != null) { msg.Dispose(); } }
Here is mail message:
PERSONAL DETAILS: -------------------------------------------------- <table border="1" cellpadding="0" cellspacing="0"><tr><td>Title:</td><td>MS</td></tr><tr><td>Family name:</td><td>As</td></tr><tr><td>Forename:</td><td>Forename</td></tr><tr><td>Gender:</td><td>Male</td></tr><tr><td>Date Of Birth:</td><td>klkj</td></tr><tr><td>Country:</td><td>BH</td></tr><tr><td>Home Telephone:</td><td></td></tr><tr><td>Mobile:</td><td></td></tr><tr><td>E-Mail:</td><td>kj@ww.ww</td></tr><tr><td>Fax No:</td><td></td></tr></table>
can anybody help me?
Star
14371 Points
2221 Posts
Feb 23, 2013 02:26 PM|LINK
Did you set the MailMessage's IsBodyHTML property to true? If not then it will be sent plain text. Try msg.IsBodyHTML = true;
Feb 23, 2013 02:30 PM|LINK
Yes I did. If you just have a look at my code..
msg.IsBodyHTML = true;
All-Star
23373 Points
2490 Posts
Microsoft
Feb 28, 2013 06:09 AM|LINK
Hi,
Please refer to the code as follow:
string emaildress1, emaildress2; string body = ""; emaildress1 = "test1@live.com"; emaildress2 = "test2@live.com"; SmtpClient client = new SmtpClient(); client.Host = "smtp.qq.com"; client.Port = 25; client.Credentials = new NetworkCredential( @"send@live.com", @"********"); // client.EnableSsl = true; // create message MailMessage message = new MailMessage(); message.From = new MailAddress("405486561@qq.com"); message.To.Add(emaildress1); message.To.Add(emaildress2); body = "<table border='1'>"; body += "<tr><td>a</td></tr>"; body += "<tr><td>b</td></tr>"; body += "<tr><td>c</td></tr>"; body += "<tr><td>d</td></tr>"; body += "<tr><td>e</td></tr>"; body += "<tr><td>f</td></tr>"; body += "<tr><td>g</td></tr>"; body += "</table>"; message.Body = body; message.BodyEncoding = System.Text.Encoding.UTF8; message.IsBodyHtml = true; message.Subject = "title"; message.SubjectEncoding = System.Text.Encoding.UTF8; // send message try { client.Send(message); } catch (SmtpException ex) { ht["error"] = ex.ToString(); } finally { message.Dispose(); }
Participant
812 Points
258 Posts
Feb 28, 2013 06:14 AM|LINK
Change AppendFormat to Append
Check all another answers
http://stackoverflow.com/questions/12350015/stringbuilders-appendformat-method-to-create-table
Member
191 Points
96 Posts
Feb 28, 2013 06:40 AM|LINK
Hi please use method for sending mail like that, and make sure that your mail bodyformt should be MailFormat.Html.
and use Append instead of using AppendFormat
public string Send_mail(string fromAddress, string toAddress, string Subject, string text) { string SERVER = "your smtp dserver name"; MailMessage ms = new System.Web.Mail.MailMessage(); ms.To = toAddress; ms.From = fromAddress; ms.Subject = Subject; ms.BodyFormat = MailFormat.Html; ms.Priority = MailPriority.High; ms.Body = text; SmtpMail.SmtpServer = SERVER; try { SmtpMail.Send(ms); ms = null; return "Sent"; } catch { ms = null; return "failed"; } }
Babiker
0 Points
17 Posts
can't formate table data in my mail
Feb 23, 2013 02:11 PM|LINK
Hi all,
I have problem with presenting data on my email.
Here is my code:
if (IsPostBack)
{
SmtpClient sc = new SmtpClient("mail.xxxx.com");
System.Text.StringBuilder sb = new System.Text.StringBuilder();
MailMessage msg = new MailMessage();
msg.IsBodyHtml = true;
sb.Append("\n");
sb.Append("PERSONAL DETAILS: \n");
sb.Append("-------------------------------------------------- \n");
sb.Append("<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\">");
sb.AppendFormat("<tr><td>Title:</td><td>{0}</td></tr>", title_1.Text.Trim());
sb.AppendFormat("<tr><td>Family name:</td><td>{0}</td></tr>", surname.Text.Trim());
sb.AppendFormat("<tr><td>Forename:</td><td>{0}</td></tr>", forename.Text.Trim());
sb.AppendFormat("<tr><td>Gender:</td><td>{0}</td></tr>", gender.Text.Trim());
sb.AppendFormat("<tr><td>Date Of Birth:</td><td>{0}</td></tr>", dob.Text.Trim());
sb.AppendFormat("<tr><td>Country:</td><td>{0}</td></tr>", Country.Text.Trim());
sb.AppendFormat("<tr><td>Home Telephone:</td><td>{0}</td></tr>", telephon.Text.Trim());
sb.AppendFormat("<tr><td>Mobile:</td><td>{0}</td></tr>", mobile.Text.Trim());
sb.AppendFormat("<tr><td>E-Mail:</td><td>{0}</td></tr>", email.Text.Trim());
sb.AppendFormat("<tr><td>Fax No:</td><td>{0}</td></tr>", fax.Text.Trim());
sb.Append("</table>");
try
{
msg = new MailMessage(email.Text,
"info@enuktranslation.co.uk", "EDUCATION PLACE REQUEST",
sb.ToString());
sc.Send(msg);
}
catch (Exception ex)
{
// something bad happened
Response.Write("Something bad happened!");
}
finally
{
if (msg != null)
{
msg.Dispose();
}
}
Here is mail message:
PERSONAL DETAILS:
--------------------------------------------------
<table border="1" cellpadding="0" cellspacing="0"><tr><td>Title:</td><td>MS</td></tr><tr><td>Family name:</td><td>As</td></tr><tr><td>Forename:</td><td>Forename</td></tr><tr><td>Gender:</td><td>Male</td></tr><tr><td>Date Of Birth:</td><td>klkj</td></tr><tr><td>Country:</td><td>BH</td></tr><tr><td>Home Telephone:</td><td></td></tr><tr><td>Mobile:</td><td></td></tr><tr><td>E-Mail:</td><td>kj@ww.ww</td></tr><tr><td>Fax No:</td><td></td></tr></table>
can anybody help me?
markfitzme
Star
14371 Points
2221 Posts
Re: can't formate table data in my mail
Feb 23, 2013 02:26 PM|LINK
Did you set the MailMessage's IsBodyHTML property to true? If not then it will be sent plain text. Try msg.IsBodyHTML = true;
Babiker
0 Points
17 Posts
Re: can't formate table data in my mail
Feb 23, 2013 02:30 PM|LINK
Yes I did. If you just have a look at my code..
msg.IsBodyHTML = true;
Catherine Sh...
All-Star
23373 Points
2490 Posts
Microsoft
Re: can't formate table data in my mail
Feb 28, 2013 06:09 AM|LINK
Hi,
Please refer to the code as follow:
string emaildress1, emaildress2; string body = ""; emaildress1 = "test1@live.com"; emaildress2 = "test2@live.com"; SmtpClient client = new SmtpClient(); client.Host = "smtp.qq.com"; client.Port = 25; client.Credentials = new NetworkCredential( @"send@live.com", @"********"); // client.EnableSsl = true; // create message MailMessage message = new MailMessage(); message.From = new MailAddress("405486561@qq.com"); message.To.Add(emaildress1); message.To.Add(emaildress2); body = "<table border='1'>"; body += "<tr><td>a</td></tr>"; body += "<tr><td>b</td></tr>"; body += "<tr><td>c</td></tr>"; body += "<tr><td>d</td></tr>"; body += "<tr><td>e</td></tr>"; body += "<tr><td>f</td></tr>"; body += "<tr><td>g</td></tr>"; body += "</table>"; message.Body = body; message.BodyEncoding = System.Text.Encoding.UTF8; message.IsBodyHtml = true; message.Subject = "title"; message.SubjectEncoding = System.Text.Encoding.UTF8; // send message try { client.Send(message); } catch (SmtpException ex) { ht["error"] = ex.ToString(); } finally { message.Dispose(); }Feedback to us
Develop and promote your apps in Windows Store
rajendraram
Participant
812 Points
258 Posts
Re: can't formate table data in my mail
Feb 28, 2013 06:14 AM|LINK
Change AppendFormat to Append
Check all another answers
http://stackoverflow.com/questions/12350015/stringbuilders-appendformat-method-to-create-table
jitendraverm...
Member
191 Points
96 Posts
Re: can't formate table data in my mail
Feb 28, 2013 06:40 AM|LINK
Hi please use method for sending mail like that, and make sure that your mail bodyformt should be MailFormat.Html.
and use Append instead of using AppendFormat
public string Send_mail(string fromAddress, string toAddress, string Subject, string text)
{
string SERVER = "your smtp dserver name";
MailMessage ms = new System.Web.Mail.MailMessage();
ms.To = toAddress;
ms.From = fromAddress;
ms.Subject = Subject;
ms.BodyFormat = MailFormat.Html;
ms.Priority = MailPriority.High;
ms.Body = text;
SmtpMail.SmtpServer = SERVER;
try
{
SmtpMail.Send(ms);
ms = null;
return "Sent";
}
catch
{
ms = null;
return "failed";
}
}