I'm trying to use the SMTP Email Settings in IIS to send mail when a POST is made to a WCF Service.
In my service I create a MailMessage like so:
MailMessage mail = new MailMessage();
// Set the to and from addresses.
// The from address must be your GMail account
mail.To.Add(new MailAddress(GetWebConfigValue("emailTo")));
mail.From = new MailAddress("mailer@me.com");
// Define the message
mail.Subject = subject;
mail.IsBodyHtml = false;
mail.Body = body;
// Create a new Smpt Client using Google's servers
var mailclient = new SmtpClient();
mailclient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
mailclient.Send(mail);
However, it always breaks when it gets to the DeliveryMethod
area stating: SmtpExecption occurred: Cannot get IIS pickup directory.
I was able to get it to work by manually defining the entries in the C# but my code needs to be a bit more configurable for multiple deployments.
I thought this approach might be a more seamless way to use IIS and this feature I needed. Anyone got any thoughts / suggestions ?
Needed to install service after configuring. This gives the details:
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.