2010-02-23 26 views
1

嗨,我有一個新的要求。我如何在郵件的正文內容中發送簡報。如何使用c#在身體中使用微軟發佈者發送電子郵件#

該通訊是由Microsoft Publisher應用程序。

請讓我知道你是否需要更多信息。

感謝

+0

'mail.IsBodyHtml = true;'? – 2010-02-23 10:41:23

+0

你目前如何發送郵件? – Ian 2010-02-23 10:41:31

+0

這是一個新的要求。我沒有使用Microsoft發佈商發送郵件的經驗。所以我在net/google搜索這個 – 2010-02-23 10:45:05

回答

1

要在.NET中發送電子郵件,使用SmtpClientMailMessageAttachment類。

MailMessage類表示郵件消息的內容。 SmtpClient類將電子郵件傳輸到您指定用於郵件傳送的SMTP主機。您可以使用附件類創建郵件附件。

假設您有一個帶有單獨樣式表和圖像的HTML時事通訊,您需要創建一個帶HTML正文內容的MailMessage並將外部文件添加爲附件。您將需要設置每個附件的ContentId屬性,並更新HTML中的引用以使用它。

正文HTML中的href附件使用cid:方案。對於id爲「xyzzy」的附件,href是「cid:xyzzy」。

爲了構建一個MAILMESSAGE用HTML體:

 string content; // this should contain HTML 

     // Create a message and set up the recipients. 
     MailMessage message = new MailMessage(
      "[email protected]", 
      "[email protected]"); 

     message.Subject = "The subject."; 
     message.Body = content; 
     message.IsBodyHtml = true; 

爲了構建一個MAILMESSAGE帶有附件:

 string file = "data.xls"; 

     // Create a message and set up the recipients. 
     MailMessage message = new MailMessage(
      "[email protected]", 
      "[email protected]"); 

     message.Subject = "The subject."; 
     message.Body = "See the attached file"; 

     // Create the file attachment for this e-mail message. 
     Attachment data = new Attachment(file, MediaTypeNames.Application.Octet); 
     data.ContentId = Guid.NewGuid().ToString(); 
     // Add time stamp iformation for the file. 
     ContentDisposition disposition = data.ContentDisposition; 
     disposition.CreationDate = System.IO.File.GetCreationTime(file); 
     disposition.ModificationDate = System.IO.File.GetLastWriteTime(file); 
     disposition.ReadDate = System.IO.File.GetLastAccessTime(file); 
     // Add the file attachment to this e-mail message. 
     message.Attachments.Add(data); 

要發送MAILMESSAGE與SmtpClient:

 //Send the message. 
     SmtpClient client = new SmtpClient(server); 
     // Add credentials if the SMTP server requires them. 
     client.Credentials = CredentialCache.DefaultNetworkCredentials; 
     client.Send(message); 
4

拉克倫羅氏有一個很好的答案。 我只想補充一點,您可能會考慮將簡報 輸出到Adobe Acrobat或圖像文件或html。

通訊定位的大多數人可能不會安裝Publisher。 因此發送它們.pub文件可能沒有預期的效果。

我推測您的客戶希望能夠在 發佈商內部啓用宏或Office應用程序,以將他們組成的電子報作爲電子郵件發送給人員列表。

Lachlans代碼會讓你發送電子郵件,我建議增加一個步驟,導出 通訊爲更普遍的格式。我相信你可以利用內置的 函數在Publisher中從你的代碼中導出。