2007-07-19

Send Email with Gmail

This sample base on vb.net 2005.

There are two step to create this.

1. You must insert mailSettings tag in app.config for window application or insert in web.config for web application.

2. Use System.Net.Mail namespace.

Sample Code for window application.
1. Insert this tag in app.config (Config Google SMTP).










2. Use System.Net.Mail namespace.


Imports System.Net.Mail

Public
Sub SendEmail()

Dim client As New SmtpClient()
Dim sendTo As New MailAddress("sendToAccount@gmail.com")
Dim from As MailAddress = New MailAddress("from@address.com")
Dim
message As New MailMessage(from,sendTo)


message.IsBodyHtml = True
message.Subject = "HI"
message.Body = "Got it!!"

' Use the same account in app.config to authenticate.
Dim basicAuthenticationInfo As New System.Net.NetworkCredential("yourAccount@gmail.com", "YourPassword")


client.Host = "smtp.gmail.com"
client.UseDefaultCredentials = False

client.Credentials = basicAuthenticationInfo
client.EnableSsl = True

Try

client.Send(message)
Console.WriteLine("SUCCESS")

Catch ex As Exception

Console.WriteLine("SEND FAIL")

End Try

End Sub

39 comments:

Unknown said...

It seems not working for me. The error message is "Failure sending mail. SEND FAIL". I am trying to send email from gmail account to other email addresses. Any idea? thanks.

TOM said...

Hi alden.
Thank you for your comment. I found some missing please try again.

Anonymous said...

thank u tom,

its really simple and effective,

for the last few months,
im looking for such a Straight forward Code,

really Great Piece of Work,

Keep going,.

Anonymous said...

Thank you so much! This is the most simplest method of all times!!!! Works perfectly :) :)
Awesome work and 2 thumbs up!! keep up the good work!! :D :D :D :D

Anonymous said...

thx
but you gotta add:
client.port = 587
:D

Anonymous said...

>thx
>but you gotta add:
>client.port = 587
>:D
Hey, just saying, I tried it without the client.port and it worked for me.
Thanks

Gaurav / Robin said...

thanks a lot .. after going through 100s of codes finally i got this working one.. really thanks again ..
just add
client.Port = 587

Gaurav , Malaysia

Anonymous said...

Nice code Thak you :)

ivory_99 said...

Hi Guys, this code did work when I used something very similar some time ago but now it keeps failing with this error msg

"No connection could be made because the target machine actively refused it 72.14.213.109:587"

Could it be something to do with the firewall of my company's n/w? Any other suggestions that could help me? Thks

Unknown said...

didnt work for me please help!!!!!!!

zms said...

Thanks a lot, it worked for me.

please make sure to turn off any anti-virus software running background in your PC :)

Anonymous said...

Hello fellow www.blogger.com members[url=http://coolnewideasou.info/forum].[/url]

I am like to introduce myself to all here[url=http://inthehottesttopics.info/forum].[/url] I have been reading this board at some times and liking to join here now[url=http://thehottesttopicsil.info/forum].[/url][url=http://evlatesttrends.info/forum].[/url]

Am glad to join here once and for all,

Please excuse my spaking english as it is not my first language[url=http://prtrendytopics.info/].[/url][url=http://vomotivationalquotes.info/].[/url]

Anonymous said...

I am using same code for rediffmail.
server="smtp.rediffmail.com"
port=25

Server response it but not authinticate credentials and username password is correct.
So please suggest me a solu for Rediffmail

Anonymous said...

It is my first message here, so I would like to say hallo to all of you! It is unquestionably pleasure to go your community!

Anonymous said...

Wow Thank you works way kool. Nice addition to my program im creating

Anonymous said...

Thank you, this worked well for me. I appreciate your help alot

Anonymous said...

Thanks for taking the time to discuss this, I really feel strongly about it and love learning more on this topic. If potential, as you achieve experience, would you thoughts updating your blog with additional data? This can be very useful for me.
hey all, I used to be simply checkin’ out this blog and I really admire the idea of the article, and have nothing to do, so if anyone want to to have an engrossing convo about it, please contact me on AIM, my title is heather smith
You ought to actually take into consideration working on developing this blog into a major authority in this market. You evidently have a grasp handle of the subjects everyone is trying to find on this web site anyways and you may actually even earn a buck or two off of some advertisements. I might explore following recent subjects and elevating the quantity of write ups you set up and I assure you’d start seeing some superb targeted visitors within the near future. Just a thought, good luck in no matter you do!
I wished to thank you for this great learn!! I definitely having fun with each little little bit of it I have you bookmarked to take a look at new stuff you publish
Thanks for taking the time to debate this, I feel strongly about it and love learning more on this topic. If attainable, as you achieve experience, would you mind updating your blog with additional info? It is extremely helpful for me.

Anonymous said...

So drunk.j..
Oh..

Doest matter

Anonymous said...

Hello my friends! Who are you!?

Anonymous said...

I really liked the article, and the very cool blog

viniel said...

i want to say thank you all of you guys here.
i have a request regarding same issue. however i want to send mail to my company's microsoft outlook. i tried many options from net but stil i hv one issue after the other. is there any way i can learn how this mail thing work n how i can do it properly. btw iam a newbi n i dnt knw much abt programming.

would be grateful foor any1's help in anyway.

Explorer said...

Try This Link

http://erp2011.blogspot.com/2011/12/erp2011-email-application.html

Anonymous said...

Hello there, I discovered your website by the use of Google while looking
for a related matter, your website came up, it appears to be
like great. I have bookmarked it in my google bookmarks.
Hi there, just turned into alert to your weblog through Google,
and located that it is really informative. I am gonna watch out for brussels.
I will appreciate in the event you continue this in future.
Lots of other people might be benefited from your writing.

Cheers!

my homepage: genf20

Anonymous said...

Undeniably believe that which you stated. Your favorite reason appeared to be on the web the easiest thing to be aware of.
I say to you, I definitely get annoyed while people think about
worries that they just don't know about. You managed to hit the nail upon the top as well as defined out the whole thing without having side effect , people could take a signal. Will probably be back to get more. Thanks

My web site Alteril Review

Anonymous said...

Very nice post. I just stumbled upon your blog
and wished to say that I have really enjoyed surfing around your blog posts.

After all I will be subscribing to your rss feed and I hope
you write again very soon!

Feel free to visit my blog post; volume pills

Anonymous said...

Great post.

Feel free to visit my web blog - growth hormone supplements

Anonymous said...

Nice post. I used to be checking constantly this weblog and I'm inspired! Extremely useful info specially the last part :) I care for such information much. I used to be seeking this certain information for a long time. Thanks and good luck.

My page - buy vigrx plus

Anonymous said...

Hello, I think your blog might be having browser compatibility issues.

When I look at your blog in Ie, it looks fine but when opening in Internet Explorer, it has some overlapping.
I just wanted to give you a quick heads up! Other then that,
wonderful blog!

My web-site - virility ex south Africa

Anonymous said...

It's nearly impossible to find educated people in this particular topic, but you sound like you know what you're talking about!
Thanks

My web site http://altawhite.eklablog.com

Anonymous said...

Please let me know if you're looking for a article author for your site. You have some really great posts and I believe I would be a good asset. If you ever want to take some of the load off, I'd absolutely love to write some content for your
blog in exchange for a link back to mine. Please shoot me an
e-mail if interested. Kudos!

My web-site :: virility ex

Anonymous said...

I think the admin of this web site is in fact working
hard in favor of his site, since here every information is quality based data.



Here is my weblog - eazol review

Anonymous said...

It's hard to come by experienced people on this topic, however, you sound like you know what you're talking about!
Thanks

my web-site ... thyromine

Anonymous said...

Pretty section of content. I just stumbled upon your website and in accession capital to assert
that I get actually enjoyed account your blog posts.
Anyway I'll be subscribing to your feeds and even I achievement you access consistently rapidly.

Here is my web site; virility Ex pill

Anonymous said...

Good web site you have got here.. It's hard to find good quality writing like yours these days. I really appreciate people like you! Take care!!

Feel free to surf to my blog post; idol lash review

Anonymous said...

This text is worth everyone's attention. How can I find out more?

Feel free to surf to my page ... capsiplex

Anonymous said...

whoah this weblog is magnificent i love studying your articles.
Keep up the great work! You already know, many individuals are searching round for this information, you can aid them greatly.


Here is my blog teeth whiteners that work

Anonymous said...

look for exactly what would finest meet your needs and try things out on different kinds of

remedies to check out what realyvision without glasses works most

effective for you.

Anonymous said...

Excellent beat ! I would like to apprentice while you amend your web site, how can i subscribe for a blog web site?

The account helped me a acceptable deal. I were tiny bit acquainted of this your broadcast provided vivid
clear concept

Here is my web blog; virility ex trial samples review

yanmaneee said...

cheap jordans
yeezy 500
nike shox for men
jordan shoes
adidas nmd r1
adidas yeezy
calvin klein underwear
nike air max
yeezy boost 350
lebron 15