Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,


Now i wanna send email by using smtp server. Successfully i done that. Here my problem is how to change my body of the image with proper space between lines. Now my delivered message subject looking like Dear User, Thanks for register in my site,Thanks and Regards, Dhinesh kumar V. But am need like

Dear User,


Thanks for register in my site.



Thanks and Regards,

Dhineshkumar V



All replies are Welcome.
Posted
Comments
bbirajdar 5-Jul-13 8:52am    
send HTML email
[no name] 5-Jul-13 8:59am    
Have you tried using carriage returns and line feeds or <br>?
Dhinesh kumar.V 5-Jul-13 9:04am    
yes am used... But result is like Dear UserSystem.Web.UI.WebControls.LiteralYour password has been changed, this is your new password 5KyU)6-P Thanks and Regards, Dhineshkumar V

try this...:)

C#
mail.Body = "Name: " + newInfo.ContactPerson + Environment.NewLine
                                + "Phone: " + newInfo.Phone + Environment.NewLine
                                + "Fax: " + newInfo.Fax + Environment.NewLine
                                + "Email: " + newInfo.Email + Environment.NewLine
                                + "Address: " + newInfo.Address + Environment.NewLine
                                + "Remarks: " + newInfo.Notes + Environment.NewLine
                                + "Giftwrap: " + rbGiftWrap.SelectedValue + Environment.NewLine
                                + "Giftwrap Instructions: " + newInfo.Instructions + Environment.NewLine + Environment.NewLine
                                + "Details: " + Environment.NewLine
                                + mailDetails;
 
Share this answer
 
Comments
Dhinesh kumar.V 5-Jul-13 9:08am    
Thanks buddy... Its works fine... I need one more thing, that is i wanna change particular word of the body in bold.
Nirav Prabtani 5-Jul-13 9:10am    
please mark and upvote it if you got your solution.
Nirav Prabtani 5-Jul-13 9:12am    
you can bold it by
"Text/b>" at codebehind...:)
Dhinesh kumar.V 5-Jul-13 9:57am    
sorry i cant get u... can you elaborate..
Nirav Prabtani 5-Jul-13 10:03am    
if you want to make text bold at code behind than you can code like that

put text between bold tag

if you want to bold label text then set label property Font-Bold="true"
This is what I would do:

C#
private void SendRegistrationMail()
{
    StringBuilder sb = new StringBuilder();

    sb.AppendLine("Dear User,");
    sb.AppendLine("");
    sb.AppendLine("Thanks for register in my site.");
    sb.AppendLine("");
    sb.AppendLine("Thanks and Regards,");
    sb.AppendLine("Dhineshkumar V");

    MailMessage message = new MailMessage();
    message.To.Add("[USER EMAIL]");
    message.Subject = "Thank you for registering";
    message.From = new MailAddress("[MY_OWN_EMAIL]");
    message.Body = (sb.ToString());
    message.IsBodyHtml = true;  //Set true to send HTML mails, false to send TEXT mails

    SmtpClient smtp = new SmtpClient("[MY_SMTP_SERVER_NAME]");

    smtp.Port = 80; //Or whatever
    smtp.EnableSsl = false; //True if your server requires SSL

    string smtpUserName = ""; //If necessary
    string smtpPassword = ""; //If necessary

    if (smtpUserName != "" && smtpPassword != "")
        smtp.Credentials = new NetworkCredential(smtpUserName, smtpPassword);

    try
    {
        smtp.Send(message);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message + Environment.NewLine + Environment.NewLine + ex.StackTrace,
                        "Couldn't send email!", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900