开发者

Send mails, using SQL Server database mail, programmaticaly

开发者 https://www.devze.com 2023-03-13 11:14 出处:网络
Is there an API to use the mail functionality (included in SQL Se开发者_JAVA技巧rver) within a .Net program ?

Is there an API to use the mail functionality (included in SQL Se开发者_JAVA技巧rver) within a .Net program ?

Can I do it without using the stored procedures ?


try using System.Mail and system.net.mail but you have to configure mail settings for that.


If you have SQL Server Database Mail set up, you have an SMTP profile.

This means you can use the inbuilt .net classes to send mail using the same SMTP profile.

Some basic code:

var message = new MailMessage(from, to, subject, body)
var smtpClient = new SmtpClient("mySMTPserver.intra.net");
smtpClient.UseDefaultCredentials = true;
smtpClient.Send(message);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号