2015-11-02 121 views
0

需要使用c#程序中的附件打開電子郵件客戶端。無法將附件文件添加到來自c#的電子郵件中

下一個C#樣品不能打開電子郵件客戶端(Outlook)中與附加的文件,並顯示錯誤信息

命令行參數是無效的。驗證使用的開關是 。

[Test] 
public void FileToEmailClient() 
{ 
    string testDataFilePath = @"..\..\Data\test.txt"; 
    Assert.That(File.Exists(testDataFilePath), Is.True); 
    string subject = String.Format("File {0} attached", Path.GetFileName(testDataFilePath)); 
    string body = "body"; 
    string command = String.Format("mailto:?subject={0}&body={1}&attachment=\"{2}\"", subject, body, testDataFilePath); 
    Process.Start(command); 
} 
+0

從一個快速的互聯網搜索,前景似乎並不支持附件。另外,您可能需要指定電子郵件地址。 –

+0

從Windows資源管理器中,我可以藉助上下文菜單命令「發送到|郵件收件人」打開帶有附件的Outlook。所以,我想要實現相同的行爲。 – constructor

回答

0

我不知道,如果「電子郵件地址」是正確的命令,但我認爲你應該能夠找到答案的Command-line switches for Outlook for Windows

試試這個(請用你的價值觀一樣的Outlook.exe的路徑替換)

var outlookPath = @"C:\Program Files\Microsoft Office 15\root\office15\OUTLOOK.EXE"; 
var command = @"/a ""C:\Temp\Signature.txt"" /m ""[email protected]&[email protected]&subject=subject&body=body"""; 
Process.Start(outlookPath, command); 

Output

+0

如果沒有「附件」部分,該命令將起作用:使用定義的主題和正文打開Outlook。但我需要發送帶有附件的電子郵件。 – constructor

+0

暫時忽略C#,只需嘗試放入命令行,cd到Office目錄並嘗試使用'/ a'開關將'OUTLOOK.EXE'傳遞給文件。對我來說,這工作得很好。 –

+0

我嘗試從Windows菜單運行mailto:?subject = File test.txt附件&body = body&attachment =「.. \\ .. \\ Data \\ test.txt」並顯示相同的錯誤 – constructor