473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Creating email messages using MailMessage class

1
I'd like to create a plain text email with a fixed font, so that I can format it such that the content falls into columns. How can I change the font of the body in a MailMessage instance? I do not want to use HTML content with <tables>.

Thanks in advance.
Mar 10 '08 #1
4 1271
tagg3rx
35
Expand|Select|Wrap|Line Numbers
  1. using System.Net.Mail;
  2. MailMessage _mMessage new MailMessage();
  3. _mMessage.To.Add("abc@123.com");
  4.  
  5. MailAddress _maFrom = new MailAddress"abc@123.com","Name");
  6. _mMessage.From = _maFrom;
  7.  
  8. _mMessage.Subject = "Subject";
  9. _mMessage.IsBodyHtml = false;
  10. _mMessage.Body = "Body";
  11.  
  12. SmtpClient _emailer = new SmtpClient();
  13. _emailer.Host = "Your smpt Server";
  14. _emailer.Port = 25;
  15.  
  16. _emailer.Send(_mMessage);
  17.  
Wala
Mar 10 '08 #2
Plater
7,872 Expert 4TB
plain text emails do NOT contain font control.
It sends "plain text", the font is determined by the client.
If you want different fonts, you need to use something other then plain text emails. (Like an html email)
Mar 10 '08 #3
Actually plaint are the text without any formatting..................

So try this code for sending Palin Text.......
if u want to create formatted one plz try HTML FORAMTTED EMAIL

protected void btn_Send_Click(object sender, EventArgs e)
{
MailMessage message = new MailMessage();
message.To = txt_To.Text;
message.From = txt_From.Text;
message.Subject = txt_Subject.Text;
message.Body = txt_Content.Text;
message.BodyFormat = MailFormat.Text;
SmtpMail.Send(message);
Response.Write("Success");
}



Nice Pgmg
************SreeRaj******
Mar 12 '08 #4
/*******This is the code for HTML Formatted Email
//************************************************** **********

Expand|Select|Wrap|Line Numbers
  1. protected void btn_Send_Click(object sender, EventArgs e)
  2.     {
  3.         MailMessage message = new MailMessage();
  4.         message.To.Add (new MailAddress(txt_To.Text));
  5.         message.From =new MailAddress(txt_From.Text);
  6.         message.Subject = txt_Subject.Text;
  7.         message.IsBodyHtml = true;
  8.         message.Priority = MailPriority.High;
  9.         StringBuilder sb = new StringBuilder();
  10.  
  11.         sb.Append("<html><body bgcolor=ligtyellow>");
  12.         sb.Append("<form id='form1' runat='server'><div>");
  13.  
  14.         sb.Append("<table align='center' width= '70%'> border=2");
  15.  
  16.         sb.Append("<tr> <td align='center' >");
  17.         sb.Append("Order No</td>");
  18.  
  19.         sb.Append("<td align='center' > ");
  20.         sb.Append("Product Name");
  21.         sb.Append("</td>");
  22.  
  23.         sb.Append(" <td align='center' >");
  24.         sb.Append("Pdoduct ID");
  25.         sb.Append("</td>");
  26.  
  27.         sb.Append("<td align='center' >");
  28.          sb.Append("Discount");
  29.         sb.Append("</td>");
  30.  
  31.         sb.Append("<td align='center' >");
  32.         sb.Append("Amount");
  33.         sb.Append(" </td>");
  34.  
  35.         sb.Append("</tr>");
  36.  
  37.         sb.Append("<tr><td align='center' >");
  38.         sb.Append("1");
  39.         sb.Append("</td>");
  40.  
  41.         sb.Append("<td align='center' >");
  42.         sb.Append("aaa"); 
  43.         sb.Append("</td>");
  44.  
  45.         sb.Append("<td align='center' >");
  46.         sb.Append("11");
  47.         sb.Append("</td>");
  48.  
  49.         sb.Append("<td align='center' >");
  50.         sb.Append("12");
  51.         sb.Append("</td>");
  52.  
  53.         sb.Append("<td align='center' >");
  54.         sb.Append("1200");
  55.         sb.Append("</td>");
  56.         sb.Append("</tr>");
  57.  
  58.         sb.Append("<tr><td align='center' >");
  59.         sb.Append("2");
  60.         sb.Append("</td>");
  61.  
  62.         sb.Append("<td align='center' >"); 
  63.         sb.Append("bb");
  64.         sb.Append("</td>");
  65.  
  66.         sb.Append("<td align='center'>");
  67.         sb.Append("22");
  68.         sb.Append("</td>");
  69.  
  70.         sb.Append("<td align='center' >");
  71.         sb.Append("33");
  72.         sb.Append("</td>");
  73.  
  74.         sb.Append("<td align='center' >");
  75.         sb.Append("300"); 
  76.         sb.Append("</td>");
  77.         sb.Append("</tr>");
  78.  
  79.         sb.Append(" <tr>");
  80.  
  81.         sb.Append("<td align='center'>"); 
  82.         sb.Append("3");
  83.         sb.Append("</td>");
  84.  
  85.         sb.Append("<td align='center'>"); 
  86.         sb.Append("cc");
  87.         sb.Append("</td>");
  88.  
  89.  
  90.         sb.Append("<td align='center'>");
  91.         sb.Append("566");
  92.         sb.Append("</td>");
  93.  
  94.         sb.Append("<td align='center'>");
  95.         sb.Append("25");
  96.         sb.Append("</td>");
  97.  
  98.         sb.Append("<td align='center'>");
  99.         sb.Append("500");
  100.         sb.Append("</td>");
  101.         sb.Append("</tr>");
  102.  
  103.         sb.Append("<tr>");
  104.         sb.Append("<td align='center'>");
  105.         sb.Append("4");
  106.         sb.Append("</td>");
  107.  
  108.         sb.Append("<td align='center'>");
  109.         sb.Append("dd");
  110.         sb.Append("</td>");
  111.  
  112.         sb.Append("<td align='center'>");
  113.         sb.Append("33");
  114.         sb.Append("</td>");
  115.  
  116.         sb.Append("<td align='center'>");
  117.         sb.Append("20");
  118.         sb.Append("</td>");
  119.  
  120.         sb.Append("<td align='centerv>"); 
  121.         sb.Append("1000"); 
  122.         sb.Append("</td>");
  123.         sb.Append("</tr>");
  124.  
  125.         sb.Append("<tr>");
  126.         sb.Append("<td align='right' colspan='3'><asp:Label ID='Label6' runat='server' Text='Total' Font-Bold='True'></asp:Label></td>");
  127.         sb.Append("<td align='center' >");
  128.         sb.Append("90");
  129.         sb.Append("</td>");
  130.  
  131.         sb.Append("<td align='center'>");
  132.         sb.Append("3000");
  133.         sb.Append("</td>");
  134.         sb.Append("</tr>");
  135.  
  136.  
  137.         sb.Append("</table></div></form>");
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.         sb.Append("</body></html>");
  145.  
  146.         message.Body = sb.ToString();
  147.  
  148.  
  149.         try
  150.         {
  151.             SmtpClient SmtpMail = new SmtpClient();
  152.  
  153.             SmtpMail.Send(message);
  154.             Response.Write("mail send successfully");
  155.  
  156.         }
  157.         catch (Exception ex)
  158.         {
  159.             Response.Write(ex);
  160.  
  161.         }
  162.  
  163.  
  164.  
  165.     }
  166.  
  167.  
Nice c#ing
************************SreeRaj*********
Mar 12 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: mike | last post by:
I have created a side application in VB.NET which reads rows from a DB and builds an email message. when i have a long string the the mailmessage.body or the mailmessage, it puts in an...
4
by: Madestro | last post by:
Hi guys, I am making a small program to retrieve e-mails from POP accounts. I got all the e-mail parsing stuff figured out, but I cannot seem to come up with a way to find out which e-mails are...
7
by: tyler_durden | last post by:
thanks a lot for all your help..I'm really appreciated... with all the help I've been getting in forums I've been able to continue my program and it's almost done, but I'm having a big problem that...
1
by: Wade Wegner | last post by:
Hello, Using the MailMessage class (or any other ASP.NET SMTP classes), I would like to programmatically request a read receipt. Is this possible? I have found an article that talked about a...
1
by: Wade Wegner | last post by:
Hello, Using the MailMessage class (or any other ASP.NET SMTP classes), I would like to programmatically request a read receipt. Is this possible? I have found an article that talked about a...
2
by: Srinivas | last post by:
Hi, I am using ASP.NET SmtpMail to send email using the following code public void SendEmail(string From, string To, string Subject, StringBuilder Message, string Attachment, string...
3
by: =?Utf-8?B?Um9iZXJ0IEUuIEZsYWhlcnR5?= | last post by:
Using .NET 2.0 in Visual Studio 2005, I am attempting to send an email. I am utilizing Yahoo as the SMTP provider. I am able to send emails using the setup instructions below using Outlook. When...
7
by: John Straumann | last post by:
Hi all: I am trying to write some code to send an email from an Assembly file, and found some examples on MSDN. However when I run the program (I am using a console app for testing), the email...
11
by: Ed Bitzer | last post by:
I have been able using the namespace System.Web.Mail and its method Smtp.mail.send to mail simple text messages to a small group within our 55 and older community. I need help expanding the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.