我想知道如何在C#中将电子邮件作为附件附加到另一个电子邮件上。
细节:
- I am writing a plugin for outlook
- I am getting the error on this line : Attachment attach = new Attachment(mailItem, new System.Net.Mime.ContentType("text/html; charset=us-ascii"));
- Error message is : Cannot create an instance of the abstract class or interface 'Microsoft.Office.Interop.Outlook.Attachment'
Sample code below
private void button1_Click(object sender, RibbonControlEventArgs e) { Explorer explorer = Globals.ThisAddIn.Application.ActiveExplorer(); Selection selection = explorer.Selection; if (selection.Count > 0) // Check that selection is not empty. { object selectedItem = selection[1]; // Index is one-based. MailItem mailItem = selectedItem as MailItem; if (mailItem != null) // Check that selected item is a message. { System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(); message.To.Add("blah@blah.com"); message.Subject = "blah"; message.From = new System.Net.Mail.MailAddress("test@test.com"); message.Body = "This is the message body"; Attachment attach = new Attachment(mailItem, new System.Net.Mime.ContentType("text/html; charset=us-ascii")); message.Attachments.Add(attach); System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smlsmtp"); smtp.Send(message); } } }