如何在C#中发送邮件之前自定义消息?
我想在文本的某处打破行,或在消息中设置特定的字体
任何人都可以帮助我吗?
代码:
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;
问候!
答案 0 :(得分:1)
只需将您的邮件发送为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");
答案 1 :(得分:0)
MailMessage.IsBodyHtml
您可以设置为true
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body,
IsBodyHtml = true // this property
})