Tag Archives: Gmail

How to use GMAIL Account to send emails

Explicit connection and Implicit connection are two secure methods to connect to a secure SMTP/SMTP/POP3 server. This topic will go in detail the Implicit connection.

Originally, a separate port was assigned to the SSL version of all these three protocols. These were 465 for SMTP/SSL, 993 for SMTP/SSL and 995 for POP3/SSL. Upon connection to this port, an SSL negotiation starts immediately and the control connection is secured. All data connections are also secured implicitly in the same way. This is similar to the approach used by HTTPS.

The code snippet below shows how to connect to the Gmail SMTP server securely using Implicit security mode and send an email using Ultimate Mail component:

C#

// Create a new instance of the SmtpClient class. 
SmtpClient client = new SmtpClient(); 
// Connect to the server. 
client.Connect("smtp.gmail.com", 465, SecurityMode.Implicit); 
// Login to the server. 
client.Authenticate("user", "password"); 
// Create a new mail message. 
MailMessage msg = new MailMessage(); 
msg.Subject = "Test Subject"; 
msg.BodyText = "Content"; 
msg.From = "from@mydomain.com"; 
msg.To = "to@somedomain.com"; 
// And send it. 
client.Send(msg); 
// Close the connection. 
client.Disconnect();

VB.NET

' Create a new instance of the SmtpClient class. 
Dim client As New SmtpClient() 
' Connect to the server. 
client.Connect("smtp.gmail.com", 465, SecurityMode.Implicit) 
' Login to the server. 
client.Authenticate("user", "password") 
' Create a new mail message. 
Dim msg As New MailMessage() 
msg.Subject = "Test Subject" 
msg.BodyText = "Content" 
msg.From = "from@mydomain.com" 
msg.To = "to@somedomain.com" 
' And send it. 
client.Send(msg) 
' Close the connection. 
client.Disconnect()