TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Sending Simple Emails with Gmail
Jhonathan Soares
May 20
2016
Code
1.1
k
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
using
System.Net;
using
System.Net.Mail;
var fromAddress =
new
MailAddress(
"
[email protected]
"
,
"From Name"
);
var toAddress =
new
MailAddress(
"
[email protected]
"
,
"To Name"
);
const
string
fromPassword =
"fromPassword"
;
const
string
subject =
"Subject"
;
const
string
body =
"Body"
;
var smtp =
new
SmtpClient
{
Host =
"smtp.gmail.com"
,
Port = 587,
EnableSsl =
true
,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials =
false
,
Credentials =
new
NetworkCredential(fromAddress.Address, fromPassword)
};
using
(var message =
new
MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}
c#