您的位置:首页 > 编程语言

编程实现sharepoint工作流中的发送邮件功能

2013-07-26 12:45 344 查看
如果你要在sharepoint工作流中实现发送邮件功能,需要
1.在管理中心设置你的smtp服务器地址,发件人信息
2.在VS2005开发的工作流中编写如下代码
using Microsoft.SharePoint.Utilities;

SPUtility.SendEmail(SPContext.Current.Web, false, false,
"to-address@mail.com", "E-mail title",
"E-mail body");
当然你也可以使用普通的.net类来发邮件(System.Net.Mail namespace)
但此方法的好处是:
你的代码中不用再进行对SMTP服务器进行配置的代码了。

用System.Net.Mail命名空间发邮件的方法是:
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Net;
using System.Net.Mail;
namespace MailSender
{
public partial class MailUtil: Page
{
protected void Page_Load(object sender, EventArgs e)
{
//邮件内容
MailMessage mail = new MailMessage("inter@18inter.com", "inter@18inter.com", "测试", "正文文");
mail.IsBodyHtml = true;
mail.Priority = MailPriority.High;
mail.ReplyTo = new MailAddress("vicky@18inter.com","vicky"); //邮件回复地址
//mail.Bcc.Add("itwind@163.com,478779122@qq.com"); //密抄

//发送邮件
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.sohu.com";
smtp.Credentials = new NetworkCredential("xxxxx@sohu.com", "*****"); //发邮件的EMIAL和密码
//smtp.EnableSsl = true; //Gmail时使用
try
{
smtp.Send(mail);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}

}
}

本文出自 “宋超技术博客” 博客,请务必保留此出处http://soungcha.blog.51cto.com/1075631/1258025
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: