Microsoft.com Home

|

Site
Map

MSDN Home

|

Developer
Centers

|

MSDN Flash

|

Subscribers

Blogs Home

Welcome Jeong!(Sign out)

Search

Bloggers

RSS

OPML

Blogs By Category

Mariya Atanasova's
Blog

Sending e-mail using SmtpClient and Gmail

This
is a simple sample that shows how to use SmtpClient to send e-mail from
your gmail account using your gmail username and
password

using
System;

using
System.Net;

using
System.Net.Mail;

namespace
GMailSample

{

class SimpleSmtpSend

{

static void Main(string[]
args)

{

SmtpClient client = new SmtpClient("smtp.gmail.com", 587);

client.EnableSsl
= true;

MailAddress from = new MailAddress("[email-masked]", "[ Your full name here]");

MailAddress to = new MailAddress("your
recipient e-mail address", "Your
recepient name");

MailMessage message = new MailMessage(from, to);

message.Body = "This is a test e-mail
message sent using gmail as a relay server ";

message.Subject = "Gmail test email
with SSL and Credentials";

NetworkCredential myCreds = new NetworkCredential("[email-masked]", "YourPassword", "");

client.Credentials = myCreds;

try

{

client.Send(message);

}

catch (Exception ex)

{

Console.WriteLine("Exception is:" +
ex.ToString());

}

Console.WriteLine("Goodbye.");

}

}

}

Published Thursday, June 15, 2006 11:23 PM by mariya

Comment Notification

Receive
email updates to this post?

You can also stay up to date using your favorite aggregator by
subscribing to the CommentRss
Feed

Comments

From My Desktop To The Internet... said:

I thought this was a pretty cool post: http://blogs.msdn.com/mariya/archive/2006/06/15/633007.aspx

Not...

June 15, 2006 7:50 PM

What do you think?

Your
URL (optional)

Comments
(required)*

Remember
Me?

This Blog

Home

Email
alerts

About

Email

Links

Post Calendar

<

June 2006

>

Su

Mo

Tu

We

Th

Fr

Sa

28

29

30

31

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

1

2

3

4

5

6

7

8

Syndication

RSS 2.0

Atom 1.0

Manage Your Profile
|Legal |Contact Us |MSDN Flash
Newsletter

©2005 Microsoft Corporation. All rights
reserved. Terms of Use
|Trademarks
|Privacy
Statement