-1

How Can I customization message before send mail in C#?
I want to break line in somewhere in text, or set specific font in message.
Can anyone help me?
pice of code:

SEPNA.BLL.Mail mail = new BLL.Mail();
        RichTextBox rtb = new RichTextBox();
        Font boldfont = new Font("B Nazanin", 14, FontStyle.Bold);
        rtb.RightToLeft = RightToLeft.Yes;
        rtb.Font = boldfont;
        SEPNA.DAL.DBMLs.COM_TbUser user = new SEPNA.DAL.Implementation.UsersDAL().GetUserByUserID(DisplayID);
        if (mailType == Types.WorkFlowMail.Mail)
        {
            switch (step)
            {
                case SEPNA.Types.FlowStep.PackageUpload:
                    rtb.Text = MessageBody.Replace("[DisplayName]", user.DisplayName).Replace("[ApplicationName]", AppName).Replace("[ActivityID]", activity).Replace("\n", new StringBuilder().AppendLine().ToString());
                    Subject = Subject.Replace("[ApplicationName]", AppName);
                    break;

Regards!

dcastro
  • 66,540
  • 21
  • 145
  • 155
Sasan
  • 644
  • 9
  • 29

2 Answers2

1

Just send your mail as html:

MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

            mail.From = new MailAddress("your_email_address@gmail.com");
            mail.To.Add("to_address");
            mail.Subject = "Test Mail - 1";

            mail.IsBodyHtml = true;
            string htmlBody;

            htmlBody = "Write some HTML code here";

            mail.Body = htmlBody;

            SmtpServer.Port = 587;
            SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
            SmtpServer.EnableSsl = true;

            SmtpServer.Send(mail);
            MessageBox.Show("mail Send"); 
Shaul Zuarets
  • 839
  • 2
  • 10
  • 20
0

MailMessage.IsBodyHtml

You can set to true

using (var message = new MailMessage(fromAddress, toAddress)
{                       
    Subject = subject,
    Body = body,
    IsBodyHtml = true // this property
})
Muhammed Tanriverdi
  • 3,230
  • 1
  • 23
  • 24