Reputation: 423
I am having a problem while sending mails through code.Actually the code is running perfectly that there is no error,but mails are not reaching to the user whom i am sending.I am pasting my code below. Please check it and tell me the problem.
System.Net.Mail.MailMessage msgMail = new System.Net.Mail.MailMessage();
msgMail.From = new System.Net.Mail.MailAddress("[email protected]");
msgMail.To.Add(new System.Net.Mail.MailAddress("[email protected]"));
string currentuseremail = web.CurrentUser.Email.ToString();
msgMail.Subject = "Request:Joing into the myitem.Title.ToString()";
msgMail.IsBodyHtml = true;
string strBody = "test mail";
msgMail.Body = strBody;
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
client.Send(msgMail);
and i configured web.config as:
<system.net>
<mailSettings>
<smtp deliveryMethod="PickupDirectoryFromIis">
<network host="smtpout.secureserver.net" port="25" defaultCredentials="true"/>
</smtp>
</mailSettings>
<settings>
<httpWebRequest useUnsafeHeaderParsing="true"/>
</settings>
</system.net>
Upvotes: 0
Views: 7196
Reputation: 15243
Set up a local directory first to receive your mail. This will rule out any code issues before you troubleshoot any further:
How to test asp.net email is being sent
<mailSettings>
<smtp deliveryMethod='SpecifiedPickupDirectory'>
<specifiedPickupDirectory pickupDirectoryLocation="c:\maildrop" />
</smtp>
</mailSettings>
<mailSettings>
<smtp from="[email protected]">
<network host="xx.xx.xxx.xx" port="25" defaultCredentials="true"/>
</smtp>
</mailSettings>
Upvotes: 1
Reputation: 81660
I believe SMTP on the machine running IIS is not configured properly or it is not running at all. You might be able to see the emails you have sent in one of the Inetpub subfolder.
Id you set PickupDirectoryFromIis, it means local SMTP server will pickup these up and relay to another SMTP.
Upvotes: 0
Reputation: 11358
Check that your local SMTP server is running. Because your DeliveryMethod
is PickupDirectoryFromIis, mails will be written to the local pickup directory to be sent by the SMTP server (which is part of IIS).
Upvotes: 0
Reputation: 29668
Surely your delivery method should be network?
http://msdn.microsoft.com/en-us/library/system.net.mail.smtpdeliverymethod.aspx
Otherwise you'll need IIS/SMTP installed on the local machine in order for the mail to be sent out, IIRC.
Upvotes: 0
Reputation: 40139
I believe the problem in your case may be with the deliveryMethod attribute in the web.config; you may have to verify with your host, but that method will dump a file for the e-mail on the web server silently, expecting a mail transfer agent to pick up the files and send them later. The network element likely isn't being used at all, since you have the PickupDirectoryFromIis value, I think.
Upvotes: 1