简体   繁体   中英

C# - Sending Email From Within SHarepoint

I would like to send an email from within sharepoint to a user on the local domain, after an event reciever has been triggered.

How would I go about this?

Any help would be much appreciated.

Many Thanks,

Freddie

You didn't really gave much context to your question, so I'm just going to point out the simplest alternative.

In most situations, you should be just be able to use one of the SPUtility.SendMail(..) overloads

So, something like this should be sufficient var headers = new StringDictionary(); headers.Add("from", from);

headers.Add("to", to);
headers.Add("cc", cc);
headers.Add("bcc", bcc);

headers.Add("subject", subject);

headers.Add("content-type", "text/html");
SPUtility.SendEmail(web, headers, body);

That said, keep in mind that SPUtility.SendEmail isn't very robust (sometimes, it won't even point out if an error occurred while sending the mail...).

For this reason, some sources prefer to just use the well documented SmtpClient instead. In that case, the only problematic part is getting the outbound email server address.

SmtpClient client = new SmtpClient();
client.Host = currentWeb.Site.WebApplication.OutboundMailServiceInstance.Server.Address;

As you can see, one possible option is getting it from the web application associated to the current web site (that is, assuming you have a valid SPContext at the time and are therefore able to access the current web site in the first place). From here, just build the MailMessage instance and send it using client.Send(message); .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM