Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi dear all,

I have configured a virtual SMTP server inside server Using inetmgr6 and email sending code is like this :-

public static Boolean SendEmailUsingGmail(some parameters)
{
SmtpClient smtp = new SmtpClient();
try
{
smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;

smtp.Send(message);

return true;

}
catch (Exception ex)
{
smtp = null;
return false;
}
}

Now the problem is that smtp.send() method always returning true while my vertual server is stopped it's not going inside catch block that's why i'm unable to maintain failure mail logs or bounced mail logic.
how to ckeck that virtual SMTP server is start or stop using c# code.

Dear, Your help and logic will appreciate me a lot.
plz provide some solution...
Posted

1 solution

Hi,

The reason why smtp.send() is returning true is because of the way you have configured smtp delivery.

You have set it up to use SmtpDeliveryMethod.PickupDirectoryFromIis.
This setting will not directly use your local smtp service, but instead delivery email to the mailroot folder location.

Hope it helps.

[Edited to add]
As the message has been successfully written to the mailroot folder, no exception will be raised.

If you modifiy your code to use a network delivery method, then exception can be raised to your asp.net code if the server is not available.
[/Edited to add]
 
Share this answer
 
v2
Comments
bholey 24-Jul-14 8:12am    
ok got it, so please suggest me, what network delivery method should we use instead of SmtpDeliveryMethod.PickupDirectoryFromIis
hypermellow 24-Jul-14 8:55am    
Hi, I usually use a delivery method of SmtpDeliveryMethod.Network.

A good example, that sends messages via gmail, is:
http://www.limilabs.com/blog/read-system-net-mailsettings-smtp-settings-web-config

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900