[英]Send Email from C# using Outlook's
i want to write application who send email using outlook and i found this link.我想编写使用 outlook 发送 email 的应用程序,我找到了这个链接。 i try this and it's perfect for me but the only thing that i miss here is the option to attach files to the mail, is it possible to do it?
我尝试了这个,它对我来说是完美的,但我在这里唯一想念的是将文件附加到邮件的选项,是否可以这样做?
Better use MailMessage instead.最好改用 MailMessage。
There's an example on how to use it with attachment here(Scroll down to "Examples"): http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.aspx这里有一个关于如何使用附件的示例(向下滚动到“示例”): http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.aspx
Not only will you get a managed framework for sending mails, but also whoever runs the code will not need Outlook installed and running.您不仅会得到一个用于发送邮件的托管框架,而且运行代码的任何人都不需要安装和运行 Outlook。
If you're stuck with outlook for some reason, try this:如果你因为某种原因卡在 outlook 上,试试这个:
using Outlook = Microsoft.Office.Interop.Outlook;
int pos = (int)email.Body.Length + 1;
int attType = (int)Outlook.OlAttachmentType.olByValue;
email.Attachments.Add("file.txt", attType, pos, "File description.");
where:在哪里:
Outlook.MailItem email = (Outlook.MailItem)_outlookAppInstance.CreateItem(Outlook.OlItemType.olMailItem);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.