using smtp to create mail sending software there was problem in body formates...

Posted by Savari_Arm under Error and Solution on 8/5/2012 | Points: 10 | Views : 1781 | Status : [Member] | Replies : 8

i am creating mail sending software using WPF & c# . the problem is my mail body content i was editing like bold, underline, and backcolor...and send to the receiver while the receiver mail was display only for text should not display the editing formats like bold ,underline and backcolor... how to handle this problem...(even i am trying mail.bodyencoding and alternative views) no one helpful for me.. any one know this problem .. help me.............




Responses

Posted by: reddysankark-13471 on: 8/5/2012 [Member] Starter | Points: 25

Up
0
Down
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

mail.From = new MailAddress("@gmail.com"); //you have to provide your gmail address as from address
mail.To.Add(to_txt.Text);
mail.Subject = subject_txt.Text;
mail.Body = message_txt.Text;

System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment(attachmentFile);
mail.Attachments.Add(attachment);

SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("@gmail.com", "password"); //you have to provide you gamil username and password
SmtpServer.EnableSsl = true;

SmtpServer.Send(mail);
Label1.Text = "Email successfully sent.";
}
catch (Exception ex)
{
Label1.Text = "Mail Send Failed !! " + ex.Message.ToString();
}

sankarreddy

Savari_Arm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Savari_Arm on: 8/6/2012 [Member] Starter | Points: 25

Up
0
Down
Please Try To Under stand my question... i am sending email is not a problem ... if formatted te xt should not display in the receiver email ... what is the reason. ...

Savari_Arm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 8/6/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
try this
 

MailMessage mailmsg = new MailMessage();
mailmsg.IsBodyHtml = True;
mailmsg.BodyEncoding = System.Text.Encoding.UTF8;
mailmsg.Body = "<table><tr><td style='font-family:Arial;font-weight:bold;font-size:12px;text-decoration:underline;'>Your Sample Message Here</td></tr></table>";


Savari_Arm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Savari_Arm on: 8/6/2012 [Member] Starter | Points: 25

Up
0
Down
right .. but my body content is richtext box text.. and using textediting controls like (Bold ,italic,underline,backcolor,forecolor).


Savari_Arm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 8/6/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
hi @Savari_Arm

if u are using RichTextEditor try this.
 string EditorData = RichTextEditor.Text;

EditorData = EditorData.Replace("\"", "'");

mailmsg.Body =EditorData;


Savari_Arm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Savari_Arm on: 8/6/2012 [Member] Starter | Points: 25

Up
0
Down
i cant under stand ... if u dont mine explain me brifly..


Savari_Arm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 8/6/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
You need to use the correct escape sequence for the quotes symbol.
above code Replace the double quotes to single quotes.
for eg:

Editor Return HTML code like
style=" font-family:Arial;font-weight:bold;font-size:12px;text-decoration:underline;"

But Mail formatting required single quote ( ' )
style=' font-family:Arial;font-weight:bold;font-size:12px;text-decoration:underline;'

Savari_Arm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Savari_Arm on: 8/6/2012 [Member] Starter | Points: 25

Up
0
Down
sorry u dont under stand my questin ..... in richtext box i have write only text and some text editing formates using editor(bold,italic& ect).. so automatically i will generated as formated text for receiver maill. how to do that.

Savari_Arm, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response