怎样使用C#调用OutLook 发送邮件? 有现成源码的吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你要的是启动outlook的程序,还是只是需要他的邮件发送功能?如果只是需要邮件发送功能,为什么要去调用outlook?outlook也是借助第三方来发送和接收邮件的 最简单发送邮件的方法是使用SmtpClient.参考使用Gmail发送邮件http://www.cnblogs.com/skywind/archive/2007/09/21/901734.html 使用outlook也可以,要使用Microsoft.Office.Interop.Outlook,也即是outlook的com组件下面的内容转自:http://tech.ddvip.com/2009-04/1238580481113103.html下面是步骤:1,添加引用Microsoft.Office.Interop.Outlook; 这个必须在Reference上面点右键,选添加才行,直接using会说找不到。 2,代码如下: Microsoft.Office.Interop.Outlook.Application outlookObj = new Microsoft.Office.Interop.Outlook.Application(); MailItem Item = (Microsoft.Office.Interop.Outlook.MailItem) outlookObj.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem); Item.To = "[email protected]"; Item.Subject = "hello"; Item.Body = "hello"; Item.Send(); 但是,恼人的是,用这个方法发送的话,Outlook会产生一个对话框,提醒用户有未知的应用程序正在冒充她的名义发送邮件。 大家可以去试试。如果找到回避这个警告框的方法,请告诉我,谢谢! 如果你有自己的smtp服务器的话,建议使用smtpclient.不过你们使用outlook应该有自己的exchange服务器。exchange服务器支持smtp的。 using System;using System.Collections.Generic;using System.Text;using System.Collections;using System.Net;using System.Net.Mail;namespace SendMail{ public class MailSend { public static void SendMail(string fromMail,List<string> toMails,List<string> CCMails,string subject,string context,List<string> filenames) { System.Net.Mail.SmtpClient smtp = new SmtpClient("你使用的SMTP主机"); System.Net.Mail.MailMessage mail = new MailMessage(); mail.From = new MailAddress(fromMail); foreach (string toMail in toMails) { mail.To.Add(new MailAddress(toMail)); } foreach (string ccmail in CCMails) { mail.CC.Add(new MailAddress(ccmail)); } foreach (string filename in filenames) { mail.Attachments.Add(new Attachment(filename)); } mail.Subject = subject; mail.Body = context; smtp.UseDefaultCredentials=false; smtp.DeliveryMethod=SmtpDeliveryMethod.Network; smtp.Send(mail); } }} 急!!!wpf浏览器应用程序部署问题 sql 中between的一些疑问 如何用DataGridView显示存储过程返回数据集 谁能说明一下sql中按多个字段排序,它到底是怎么排的? 新手求教 多线程调试问题! dropdownlist下拉出来的内容太宽,有什么方法可以完整显示? 问一个字符串转化成表达式的问题??? 在网上看到一个很有趣的问题。特来向各位大哥请教。 未能找到任何适合于指定的区域性或非特定区域性的资源 C#可以像JAVA一样嵌到网页中去吗? C#使用 SqlDataAdapter类能不能调用存储过程啊? 求一完全开源的电子商务网站系统?急急急急急急急
参考
使用Gmail发送邮件
http://www.cnblogs.com/skywind/archive/2007/09/21/901734.html
下面的内容转自:http://tech.ddvip.com/2009-04/1238580481113103.html
下面是步骤:1,添加引用Microsoft.Office.Interop.Outlook; 这个必须在Reference上面点右键,选添加才行,直接using会说找不到。 2,代码如下: Microsoft.Office.Interop.Outlook.Application outlookObj = new Microsoft.Office.Interop.Outlook.Application();
MailItem Item = (Microsoft.Office.Interop.Outlook.MailItem)
outlookObj.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
Item.To = "[email protected]"; Item.Subject = "hello"; Item.Body = "hello"; Item.Send(); 但是,恼人的是,用这个方法发送的话,Outlook会产生一个对话框,提醒用户有未知的应用程序正在冒充她的名义发送邮件。 大家可以去试试。如果找到回避这个警告框的方法,请告诉我,谢谢!
不过你们使用outlook应该有自己的exchange服务器。exchange服务器支持smtp的。
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Net;
using System.Net.Mail;namespace SendMail
{
public class MailSend
{
public static void SendMail(string fromMail,List<string> toMails,List<string> CCMails,string subject,string context,List<string> filenames)
{
System.Net.Mail.SmtpClient smtp = new SmtpClient("你使用的SMTP主机");
System.Net.Mail.MailMessage mail = new MailMessage();
mail.From = new MailAddress(fromMail);
foreach (string toMail in toMails)
{
mail.To.Add(new MailAddress(toMail));
} foreach (string ccmail in CCMails)
{
mail.CC.Add(new MailAddress(ccmail));
} foreach (string filename in filenames)
{
mail.Attachments.Add(new Attachment(filename));
} mail.Subject = subject;
mail.Body = context;
smtp.UseDefaultCredentials=false;
smtp.DeliveryMethod=SmtpDeliveryMethod.Network;
smtp.Send(mail);
}
}
}