I am trying to send mail with following code. OS is windows 2008 server. SMTP is installed.
MailMessage message = new MailMessage();
string[] recipientslist = recipients.Split(';');
foreach (string recipient in recipientslist)
{
if (!String.IsNullOrEmpty(recipient))
{
System.Net.Mail.MailAddress mailAddress =
new System.Net.Mail.MailAddress(recipient);
message.To.Add(mailAddress.Address);
}
}
message.From = new MailAddress(sender);
message.Subject = subject;
message.Body = body;
SmtpClient smtpClient = new SmtpClient();
smtpClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
smtpClient.UseDefaultCredentials = true;
smtpClient.Send(message);
In web.config
<system.net>
<mailSettings>
<smtp deliveryMethod="PickupDirectoryFromIis">
<network host="localhost" port="25" defaultCredentials="true" />
</smtp>
</mailSettings>
</system.net>
Even SMTP is installed, I'm getting
Exception: Failure sending mail.
Stack Trace: at System.Net.Mail.SmtpClient.Send(MailMessage message)....
The other scenario when SMTP is not installed, it giving me the exception Cannot get IIS pickup directory.