通过C#通过Outlook 2010发送电子邮件 [英] Sending Email through Outlook 2010 via C#
本文介绍了通过C#通过Outlook 2010发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从我的C#控制台应用程序内发送电子邮件。我已经加入了参考和使用报表,但现在看来还没有添加我需要的一切。这是第一次我曾经尝试这样做,所以我想有一些我已经忘记了。
我从MSDN网站的 http://msdn.microsoft.com/en-us/库/ vstudio / ms269113(v = VS.100)的.aspx
下面是我在2010年获得VS问题的代码
使用系统;
使用System.Configuration;
:使用System.IO;使用System.Net
;
使用System.Net.Mail;使用System.Runtime.InteropServices
;使用Outlook = Microsoft.Office.Interop.Outlook
;使用Office = Microsoft.Office.Core
;
命名空间FileOrganizer
{
类节目
{
私人无效CreateMailItem()
{
//Outlook.MailItem的MailItem =(Outlook.MailItem)
// this.Application.CreateItem(Outlook.OlItemType.olMailItem);
Outlook.Application应用=新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(假);
}
}
}
解决方案
替换行
Outlook.MailItem的MailItem =(Outlook.MailItem)
this.Application.CreateItem (Outlook.OlItemType.olMailItem);
与
Microsoft.Office.Interop.Outlook.Application应用=新Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem的MailItem = app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
希望这帮助,
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,
这篇关于通过C#通过Outlook 2010发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文