0

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.

4
  • those snippets are not very helpful.. some pointers: can you connect to local smtp using telnet? paste the exception details Commented Apr 30, 2012 at 14:28
  • Does your IIS user have write permission to the pickup directory? Also, have you tried using the Network delivery method instead of PickupDirectoryFromIis? Commented Apr 30, 2012 at 14:36
  • @Osama: I can connect to local smtp using telnet. Exception is not informative "Exception: Failure sending mail. Stack Trace: at System.Net.Mail.SmtpClient.Send(MailMessage message) at QH.ExchangeProtection.Util.CommonUtil.SendMail(String sender, String recipients, String subject, String body)" Commented May 1, 2012 at 6:50
  • @JamieSee: I am newbie to c# and networking concepts. with the Network delivery method giving same exception Commented May 1, 2012 at 7:16

2 Answers 2

1

I got the answer..

Permission is needed to default IIS pickup directory. I just added permissions for Network service and done.

Following is the check list that should be verified before sending mail.. http://torontoprogrammer.ca/2011/04/fixing-the-cannot-get-iis-pickup-directory-error-in-asp-net/

Thanks

Sign up to request clarification or add additional context in comments.

Comments

0

This is an anti-virus program, QH Exchange Protection, interfering with sending mail from the application. Contact your system administrator about this. If you are the administrator of your system, you'll need to find out how to tell Quick Heal's product not to do this.

1 Comment

Yeah, and how you know that it is this specific program installed there?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.