-----------------------------------------------------------
New Message on BDOTNET
-----------------------------------------------------------
From: DotNetSaavy (Mr.BabuRaj)
Message 1 in Discussion
Hi all,
>From my C# windows application , on click of a button I'm sending a mail using the
>following code.
Inspite after setting the BodyFormat to HTML as below, I still get the HTML tags in
the mail body.
How to I get rid of this and display the contents underlined in bold.Please reply
MailMessage mailmessage=new MailMessage();
mailmessage.Body="<html><u><b>This is a mail with HTML content</b></u></html>";
mailmessage.Subject=subject;
mailmessage.BodyFormat=MailFormat.Html;
mailmessage.From="AHMS Mail Administrator";
Send(mailmessage);
public static bool Send(MailMessage message)
{
IPHostEntry IPhst = Dns.Resolve(ConfigVO.getStngsMailSvr());
IPEndPoint endPt = new IPEndPoint(IPhst.AddressList[0], 25);
Socket s= new Socket(endPt.AddressFamily, SocketType.Stream,ProtocolType.Tcp);
s.Connect(endPt); if(!Check_Response(s, SMTPResponse.CONNECT_SUCCESS))
{
s.Close();
return false;
} Senddata(s, string.Format("HELO {0}\r\n", Dns.GetHostName() ));
if(!Check_Response(s, SMTPResponse.GENERIC_SUCCESS))
{
s.Close();
return false;
} Senddata(s, string.Format("MAIL From: {0}\r\n", message.From ));
if(!Check_Response(s, SMTPResponse.GENERIC_SUCCESS))
{
s.Close();
return false;
} string _To = message.To;
string[] Tos= _To.Split(new char[] {';'});
foreach (string To in Tos)
{
Senddata(s, string.Format("RCPT TO: {0}\r\n", To));
if(!Check_Response(s, SMTPResponse.GENERIC_SUCCESS))
{
s.Close();
return false;
}
} if(message.Cc!=null)
{
Tos= message.Cc.Split(new char[] {';'});
foreach (string To in Tos)
{
Senddata(s, string.Format("RCPT TO: {0}\r\n", To));
if(!Check_Response(s, SMTPResponse.GENERIC_SUCCESS))
{
s.Close();
return false;
}
}
} StringBuilder Header=new StringBuilder();
Header.Append("From: " + message.From + "\r\n");
Tos= message.To.Split(new char[] {';'});
Header.Append("To: ");
for( int i=0; i< Tos.Length; i++)
{
Header.Append( i > 0 ? "," : "" );
Header.Append(Tos[i]);
}
Header.Append("\r\n");
if(message.Cc!=null)
{
Tos= message.Cc.Split(new char[] {';'});
Header.Append("Cc: ");
for( int i=0; i< Tos.Length; i++)
{
Header.Append( i > 0 ? "," : "" );
Header.Append(Tos[i]);
}
Header.Append("\r\n");
}
Header.Append( "Date: " );
Header.Append(DateTime.Now.ToString("ddd, d M y H:m:s z" ));
Header.Append("\r\n");
Header.Append("Subject: " + message.Subject+ "\r\n");
Header.Append( "X-Mailer: SMTPDirect v1\r\n" );
string MsgBody = message.Body;
if(!MsgBody.EndsWith("\r\n"))
MsgBody+="\r\n";
if(message.Attachments.Count>0)
{
Header.Append( "MIME-Version: 1.0\r\n" );
Header.Append( "Content-Type: multipart/mixed; boundary=unique-boundary-1\r\n" );
Header.Append("\r\n");
Header.Append( "This is a multi-part message in MIME format.\r\n" );
StringBuilder sb = new StringBuilder();
sb.Append("--unique-boundary-1\r\n");
sb.Append("Content-Type: text/plain\r\n");
sb.Append("Content-Transfer-Encoding: 7Bit\r\n");
sb.Append("\r\n");
sb.Append(MsgBody + "\r\n");
sb.Append("\r\n"); foreach(object o in message.Attachments)
{
MailAttachment a = o as MailAttachment;
byte[] binaryData;
if(a!=null)
{
FileInfo f = new FileInfo(a.Filename);
sb.Append("--unique-boundary-1\r\n");
sb.Append("Content-Type: application/octet-stream; file=" + f.Name + "\r\n");
sb.Append("Content-Transfer-Encoding: base64\r\n");
sb.Append("Content-Disposition: attachment; filename=" + f.Name + "\r\n");
sb.Append("\r\n");
FileStream fs = f.OpenRead();
binaryData = new Byte[fs.Length];
long bytesRead = fs.Read(binaryData, 0, (int)fs.Length);
fs.Close();
string base64String =
System.Convert.ToBase64String(binaryData,0,binaryData.Length); for(int i=0; i<
base64String.Length ; )
{
int nextchunk=100;
if(base64String.Length - (i + nextchunk ) <0)
nextchunk = base64String.Length -i;
sb.Append(base64String.Substring(i, nextchunk));
sb.Append("\r\n");
i+=nextchunk;
}
sb.Append("\r\n");
}
}
MsgBody=sb.ToString();
} Senddata(s, ("DATA\r\n"));
if(!Check_Response(s, SMTPResponse.DATA_SUCCESS))
{
s.Close();
return false;
}
Header.Append( "\r\n" );
Header.Append( MsgBody );
Header.Append( ".\r\n" );
Header.Append( "\r\n" );
Header.Append( "\r\n" );
Senddata(s, Header.ToString());
if(!Check_Response(s, SMTPResponse.GENERIC_SUCCESS ))
{
s.Close();
return false;
} Senddata(s, "QUIT\r\n");
Check_Response(s, SMTPResponse.QUIT_SUCCESS );
s.Close();
return true;
} Thanks BabuRaj
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/BDotNet/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you received
this message by mistake, please click the "Remove" link below. On the pre-addressed
e-mail message that opens, simply click "Send". Your e-mail address will be deleted
from this group's mailing list.
mailto:[EMAIL PROTECTED]