Setup smtp client for gmail in asp.net 4

Asp.net 4 provides a nice feature that you can setup you smtp client for those providers requiring ssl secure connection. Taking gmail for an example, if you are setting the smtp through web.config file at the root of your website, it should look like this:

<configuration>

……
    <system.net>
        <mailSettings>
            <smtp deliveryMethod=”Network” from=”name &lt;yourname@gmail.com&gt;”>
                <network enableSsl=”true” host=”smtp.gmail.com” password=”yourpassword” userName=”username@gmail.com” port=”587″/>
            </smtp>
        </mailSettings>
    </system.net>
</configuration>

So the enableSsl=”true” allows the SSL connection and you need to write out explicitly the right port number, 587 in this case (I tried 465 or leave it blank. In both cases, the smtp doesn’t work properly.).

A quick reminder: you can always set the deliveryMethod = “SpecifiedPickupPlace” to send email to local folder during development time

菊子曰 今天你菊子曰了么?
Advertisement
Explore posts in the same categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.