2011-09-12 51 views
2

我目前有現有的代碼可以自動執行併發送電子郵件和發送文件。我現在需要添加一個cc。我已經看遍了所有,但似乎無法找到與我現有的代碼。任何幫助將不勝感激。謝謝。Microsoft Outlook將cc添加到電子郵件

  private void button13_Click(object sender, EventArgs e) 
    { 
     //Send Routing and Drawing to Dan 
     // Create the Outlook application by using inline initialization. 
     Outlook.Application oApp = new Outlook.Application(); 
     //Create the new message by using the simplest approach. 
     Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem); 
     //Add a recipient 
     Outlook.Recipient oRecip = (Outlook.Recipient)oMsg.Recipients.Add("[email protected]"); 
     oRecip.Resolve(); 
     //Set the basic properties. 
     oMsg.Subject = "Job # " + textBox9.Text + " Release (" + textBox1.Text + ")"; 
     oMsg.HTMLBody = "<html><body>"; 
     oMsg.HTMLBody += "Job # " + textBox9.Text + " is ready for release attached is the Print and Routing (" + textBox1.Text + ")"; 
     oMsg.HTMLBody += "<p><a href='C:\\Users\\RussellS\\Desktop\\Russell Eng Reference\\" + textBox1.Text + ".PDF'>" + textBox1.Text + " Drawing"; 
     oMsg.HTMLBody += "<p><a href='C:\\Users\\RussellS\\Desktop\\" + textBox1.Text + ".PDF'>" + textBox1.Text + " Routing" + "</a></p></body></html>"; 
     //Send the message 
     oMsg.Send(); 
     //Explicitly release objects. 
     oRecip = null; 
     oMsg = null; 
     oApp = null; 
     MessageBox.Show(textBox1.Text + " Print and Routing Sent"); 
    } 

回答

3

根據MSDN,MailItem類有一個CC屬性。

string CC { get; set; } 

可以用來設置CC收件人的姓名。

http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook._mailitem.cc.aspx

要修改收件人可以將其添加到收件人集合:

http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.recipients.aspx

,你會使用這樣的:

oMsg.Recipients.Add("[email protected]"); 
+0

的實際工作,但它增加到的TO:在展望,而不是cc,所以我會以某種方式不得不在字符串中的CC字符串? –

+0

據我所知,將CC收件人的名稱設置爲與收件人集合中的收件人匹配的東西就足夠了。 –

+7

我知道這個答案被接受,我只是想補充一點,微軟建議你通過收件人收集來操作收件人。 To,CC和BCC屬性應僅用於讀取收件人。要設置CC收件人,您可以在Jamie上面添加新收件人的代碼之後立即將Type屬性設置爲olCC(或對於BCC收件人爲olBCC)。 – JimmyPena

相關問題