2009-09-09 126 views
1

我看了看互聯網,但看不到任何相關的東西。我只想在outllook上開始一封新郵件,但不想發送,因爲用戶可能希望將他們自己的內容添加到電子郵件中,而我所有的程序正在添加一個地址和附件。VB.Net電子郵件發送

任何幫助將不勝感激。

+0

非常感謝您的幫助。我植入了一些建議,並使用com包裝器工作。我還記得我有一些舊代碼在一個非常舊的版本庫中執行過。再一次感謝你。 – 2009-09-09 12:21:56

回答

4

您可以在Outlook可執行文件上調用Process.Start。 有切換到自動填充消息以及..

打開新郵件:

outlook.exe /c ipm.note 

打開一封新郵件並填寫發件人:

outlook.exe /c ipm.note /m [email protected] 

打開新郵件帶附件的消息:

outlook.exe /c ipm.note /a filename 

組合:

outlook.exe /c ipm.note /m [email protected]&subject=test%20subject&body=test%20body 
5

下面是一個例子 - http://support.microsoft.com/kb/310263

// 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. 
// TODO: Change the following recipient where appropriate. 
Outlook.Recipient oRecip = (Outlook.Recipient)oMsg.Recipients.Add("e-mail address"); 
oRecip.Resolve(); 

//Set the basic properties. 
oMsg.Subject = "This is the subject of the test message"; 
oMsg.Body = "This is the text in the message."; 

//Add an attachment. 
// TODO: change file path where appropriate 
String sSource = "C:\\setupxlg.txt"; 
String sDisplayName = "MyFirstAttachment"; 
int iPosition = (int)oMsg.Body.Length + 1; 
int iAttachType = (int)Outlook.OlAttachmentType.olByValue; 
Outlook.Attachment oAttach = oMsg.Attachments.Add(sSource,iAttachType,iPosition,sDisplayName); 

// If you want to, display the message. 
// oMsg.Display(true); //modal 

//Send the message. 
oMsg.Save(); 
oMsg.Send(); 

//Explicitly release objects. 
oRecip = null; 
oAttach = null; 
oMsg = null; 
oApp = null; 
+0

這種方法非常好,只需要包含VSTO組件的一個缺點。 – Jirapong 2009-09-09 11:39:57

2

可以使用的Process.Start( 「電子郵件地址:XXX」)格式。它會調出默認的郵件客戶端格式,你把它寄到。

string mailto = string.Format(
      "mailto:{0}?Subject={1}&Body={2}&Attach={3}", 
      address,subject,body,attach); 

System.Diagnostics.Process.Start(mailto) 

對不起,在C#中回答。

1

要做到這一點,最簡單的方法是使用Outlook COM互操作 - 只需添加一個COM引用到Outlook(如果已安裝它應該使用主Interop大會)

因此,像:

Dim m_Email As New Microsoft.Office.Interop.Outlook.ApplicationClass 
dim m_Message As Microsoft.Office.Interop.Outlook.MailItem = m_Email.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem) 
m_Message.To = "[email protected]" 
m_Message.Subject = "Subject"