通过Outlook 2010通过C#发送电子邮件 [英] Sending Email through Outlook 2010 via C#
本文介绍了通过Outlook 2010通过C#发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从MSDN网站获得了这个代码片段 http://msdn.microsoft.com/en-us /library/vstudio/ms269113(v=vs.100).aspx
以下是我在VS 2010中遇到问题的代码
using System;新新200新新旗新新新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新旗新新新200新新旗新新新子:
使用System.Net;
使用System.Net.Mail;
使用System.Runtime.InteropServices;
使用Outlook = Microsoft.Office.Interop.Outlook;
使用Office = Microsoft.Office.Core;
命名空间FileOrganizer
{
类程序
{
private void CreateMailItem()
{
//Outlook.MailItem mailItem =(Outlook.MailItem)
// this.Application.CreateItem(Outlook.OlItemType.olMailItem);
Outlook.Application app = new Outlook.Application();
Outlook.MailItem mailItem = app.CreateItem(Outlook.OlItemType.olMailItem);
mailItem.Subject =这是主题;
mailItem.To =someone@example.com;
mailItem.Body =这是消息。;
mailItem.Attachments.Add(logPath); // logPath是一个字符串,保存log.txt文件的路径
mailItem.Importance = Outlook.OlImportance.olImportanceHigh;
mailItem.Display(false);
}
}
}
解决方案
替换行
Outlook.MailItem mailItem =(Outlook.MailItem)
this.Application.CreateItem (Outlook.OlItemType.olMailItem);
与
Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem mailItem = app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
希望这个新新p新新新新旗新新旗旗新新旗旗新新旗旗新新旗旗新新旗旗新新新旗新旗新新旗旗
I am trying to send an email from inside my C# console App. I have added the references and using statements but it seems I have not added everything I need. This is the first time I have ever attempted to do this so I figure there is something I have forgotten.
I got this code snippet from the MSDN site http://msdn.microsoft.com/en-us/library/vstudio/ms269113(v=vs.100).aspx
Here is the code that I am getting issues with in VS 2010
using System;
using System.Configuration;
using System.IO;
using System.Net;
using System.Net.Mail;
using System.Runtime.InteropServices;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
namespace FileOrganizer
{
class Program
{
private void CreateMailItem()
{
//Outlook.MailItem mailItem = (Outlook.MailItem)
// this.Application.CreateItem(Outlook.OlItemType.olMailItem);
Outlook.Application app = new Outlook.Application();
Outlook.MailItem mailItem = app.CreateItem(Outlook.OlItemType.olMailItem);
mailItem.Subject = "This is the subject";
mailItem.To = "someone@example.com";
mailItem.Body = "This is the message.";
mailItem.Attachments.Add(logPath);//logPath is a string holding path to the log.txt file
mailItem.Importance = Outlook.OlImportance.olImportanceHigh;
mailItem.Display(false);
}
}
}
解决方案
replace the line
Outlook.MailItem mailItem = (Outlook.MailItem)
this.Application.CreateItem(Outlook.OlItemType.olMailItem);
with
Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem mailItem = app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
Hope this helps,
这篇关于通过Outlook 2010通过C#发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文