|
1. 使用SPUtility.SendEmail, 命名空间: Microsoft.SharePoint.Utilities程序集: Microsoft.SharePoint (in Microsoft.SharePoint.dll):
StringDictionary headers = new StringDictionary();headers.add("to",someone@somewhere.com);headers.add("cc",someone.else@somewhere.com);headers.add("bcc",somebody@somewhere.com);headers.add("from",sender@somewhere.com);headers.add("subject","SPUtility.SendEmail with headers test");string bodyText ="Email body";SPUtility.SendEmail(web, headers, bodyText); 具体参考http://msdn.microsoft.com/en-us/library/ms460489.aspx
2. 使用MailMessage, 命名空间: System.Web.Mail程序集:System.Web (in System.Web.dll)
MailMessage MyMail = new MailMessage();MyMail.From = sFrom;MyMail.To = sTo;MyMail.Subject = sSubject;MyMail.Body = sBody;MyMail.Cc = sCc;MyMail.Bcc = sBcc;MyMail.UrlContentBase = sUrlContentBase;MyMail.UrlContentLocation = sUrlContentLocation;if (txtBodyEncoding.Text == Encoding.UTF7.EncodingName)MyMail.BodyEncoding = Encoding.UTF7;else if (txtBodyEncoding.Text == Encoding.UTF8.EncodingName)MyMail.BodyEncoding = Encoding.UTF8;elseMyMail.BodyEncoding = Encoding.ASCII;switch (sBodyFormat.ToUpper()){case "HTML": MyMail.BodyFormat = MailFormat.Html;break;default: MyMail.BodyFormat = MailFormat.Text;break;}switch (sPriority.ToUpper()){case "HIGH": MyMail.Priority = MailPriority.High;break;case "LOW": MyMail.Priority = MailPriority.Low;break;default: MyMail.Priority = MailPriority.Normal;break;}// Build an IList of mail attachments.if (sAttach != ""){char[] delim = new char[] {','};foreach (string sSubstr in sAttach.Split(delim)){MailAttachment MyAttachment = new MailAttachment(sSubstr);MyMail.Attachments.Add(MyAttachment);}}SmtpMail.SmtpServer = sMailServer;SmtpMail.Send(MyMail); 具体参考http://msdn.microsoft.com/en-us/library/system.web.mail.mailmessage(v=VS.100).aspx |
|
|