2014-10-29 2 views
-1

어떻게 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

로 설정할 수 있습니다. – Dave

답변

1

그냥 HTML로 메일을 보내

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

      mail.From = new MailAddress("[email protected]"); 
      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"); 
+0

Google에 대한 크레딧 : –

+0

나는 당신의'mail.To.Add ("")'가 정말로 마음에 듭니다. 방금 각 이메일 끝에 ';'과 함께 문자열을 사용했습니다. –

0

MailMessage.IsBodyHtml

을 당신은 우리에게 당신의 코드와 당신이 이미 시도를 보여주십시오 진정한

using (var message = new MailMessage(fromAddress, toAddress) 
{      
    Subject = subject, 
    Body = body, 
    IsBodyHtml = true // this property 
}) 
관련 문제