Reputation: 3156
I am getting following error message while sending email through SMTP service:
I have following SMTP setting on my system:
Operating system: Windows 7 Home Premium
IIS: IIS 7
How can i resolve this problem?
Thanks.
Upvotes: 2
Views: 1677
Reputation: 688
Based on the inner exception and your code, you're trying to send mail via 127.0.0.1.
Removing the line in your code that is setting the smtp host to 127.0.0.1 should cause the site to use the SMTP settings as defined in IIS.
As SMTP settings will usually vary in between server setups, live / test environments, it is usually best to not hard-code SMTP settings such as Host in your code and instead to set the settings via IIS (which actually takes from web.config's section system.net/mailSettings).
Edit:
As your web.config doesn't have a mailSettings section, I would assume you took the screenshot from the SMTP Email in IIS7 in the server view. There's a similar section in the website view.
You can manually add the mailSettings to the web.config: I usually do so.
For your setup (ie, storing emails as file in a directory), the following would be needed:
<system.net>
<mailSettings>
<smtp deliveryMethod="specifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="c:\inetpub" />
</smtp>
</mailSettings>
</system.net>
Note that this wouldn't send emails, but just store them in the folder for a SMTP server to pick them up. To send them, you'll need to setup a SMTP server or connect to a third party one like http://sendgrid.com.
Upvotes: 1
Reputation: 124686
I would suggest you look at the exception detail, including any inner exception. To hazard a guess, maybe you don't have permission to write to C:\Inetpub.
Upvotes: 0