2014-09-22 26 views
0

mailItem.HTMLBody =「多個顏色字體在一個html電子郵件中

尊敬的IT部門

您收到了一個新的」+ comboBox3.Text +「優先級任務,從」+ textBox1.Text +「完成。

完成後請聯繫「+ textBox2.Text +」進行確認任務已完成,以符合他們的期望

任務如下:

「+ richTextBox1.Text +「

親切的問候,

」+ textBox1.Text +「

「;

我基本上想突出顯示文本/組合框或至少改變它們的字體顏色。令人煩惱的是,你看不到我使用的HTML代碼,但它應該很明顯,但我嘗試使用字體顏色......沒有運氣。不能看到我要去哪裏錯

回答

1

我可以看到,你試着把textBox2.txt的價值。你的錯誤是將textBox2.txt寫成一個字符串內容。因此,您可以使用string.Format方法來實現此目的。

你應該這樣來改變它:

mailItem.HTMLBody = string.Format("<html><body><p>Dear IT Dept.</p> <p>You have   received a new task to complete from ({0}) Please check the attached file and  fit the task in to your schedule.</p><p> Once completed please contact the provided contactee for comfirmation the task is completed to thier expectations.</p>", textBox2.Text); 

注意textBox2.Text and{0}元素。 注意:您也錯誤TextBox.Text屬性的語法。

+0

謝謝!添加多個我會增加數字,所以{0}將{1},然後在第一個尾部後面定義第二個字符串? – 2014-09-22 08:46:05

+0

是的。有關詳細信息,請查看此頁http://www.dotnetperls.com/string-format。順便說一下,不要忘記讓我快樂與標記爲接受答案我的回答:) – 2014-09-22 08:53:46

1

你需要有:中

mailItem.HTMLBody = "<html><body>... from " + textBox2.Text + " Please ..."; 

代替

mailItem.HTMLBody = "<html><body>... from (textBox2.txt) Please ..."; 
0

你的意思是:

mailItem.HTMLBody = "<html><body><p>Dear IT Dept.</p> <p>You have   received a new task to complete from " + textBox2.Text + " Please check the attached file and  fit the task in to your schedule.</p><p> Once completed please contact the provided contactee for comfirmation the task is completed to thier expectations.</p>"; 

在您的版本中,「textbox2.txt」將作爲字符串操作,不會被「解析」。 在我的這是一個控制你的表格,我們把它的文本內容在郵件中。

編輯:你問到如何emphase變量,這裏是一個例子: 試着這麼做

mailItem.HTMLBody = "<html><body><p>Dear IT Dept.</p> <p>You have received a new task to complete from <strong>" + textBox2.Text + "</strong> Please check the attached file and fit the task in to your schedule.</p><p> Once completed please contact the provided contactee for comfirmation the task is completed to thier expectations.</p>"; 

在你的變量的「強勢」標籤將會把名稱加粗。

+0

感謝哥們,看起來像最簡單的方式! – 2014-09-22 08:47:11

+0

您是否知道我將如何突出顯示變量或更改文本顏色以使它們在電子郵件中脫穎而出? – 2014-09-22 09:55:29

+0

在html中?我已經編輯了我的答案,上面添加了一個示例。不要猶豫,投票我的答案,因爲它是有幫助的。祝你好運 – AFract 2014-09-22 20:30:28

1

MailMessage類中沒有HTMLBody屬性(假設這是您正在使用的?)。

這只是Body

你會做這樣的事情:

mailItem.Body = string.Format("<html><body><p>Dear {0}.</p>", comboBox3.Text); 

等...

0
   var mailItem= new MailMessage(); 
       SmtpClient SmtpServer = new SmtpClient("smtp server addess"); 

       mailItem.From = new MailAddress("[email protected]"); 
       mailItem.To.Add("[email protected]???.co.uk"); 


        mailItem.Subject = string.Format("You have a new task from {0}", comboBox3.Text); 
        mailItem.To = ""; 
        mailItem.Body =string.Format("<html><body><p>Dear IT Dept.</p> <p>You have   received a new task to complete from {0} Please check the attached file and  fit the task in to your schedule.</p><p> Once completed please contact the provided contactee for comfirmation the task is completed to their expectations.</p>",textBox2.txt); 

        attachment = new System.Net.Mail.Attachment(@"\\??-filesvr\shares\Shared\+++++Web Projects+++++\????\IssueReport.txt"); 
        mailItem.Attachments.Add(@"\\??-filesvr\shares\Shared\+++++Web Projects+++++\??\IssueReport.txt"); 

        mailItem.IsBodyHtml = true; 

       // Optional Items based on your smtp server. 
       /* SmtpServer.Port = 587; 
       SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password"); 
       SmtpServer.EnableSsl = true;*/ 

       SmtpServer.Send(mailItem); 
       MessageBox.Show("mail Send"); 
相關問題