You can use a Gmail account to receive, read, modify, and send email messages using the Ultimate Mail component. Gmail only accepts secure connections with the configuration shown in the table below:
Protocol | Port | Security Mode | Server |
---|---|---|---|
IMAP | 993 | Implicit | imap.gmail.com |
POP3 | 995 | Implicit | pop.gmail.com |
SMTP | 465 | Implicit | smtp.gmail.com |
The following example code shows how to connect to Gmail IMAP, POP3, and SMTP servers:
// Create a new instance of the Imap class and download a message.
using (Imap client = new Imap())
{
// Connect to the server.
client.Connect("imap.gmail.com", 993, SecurityMode.Implicit);
// Login to the server.
client.Authenticate("test@domain.com", "password");
// Download a message to an instance of the MailMessage class.
MailMessage msg = client.DownloadMailMessage(imapMessageUniqueId);
}
// Create a new instance of the Pop3 class and download a message.
using (Pop3 client = new Pop3())
{
// Connect to the server.
client.Connect("pop.gmail.com", 995, SecurityMode.Implicit);
// Login to the server.
client.Authenticate("test@domain.com", "password");
// Download the message to an instance of the MailMessage class.
MailMessage msg = client.DownloadMailMessage(pop3MessageSequenceNumber);
}
// Create a new instance of the Smtp class and send an email.
using (Smtp client = new Smtp())
{
// Connect to the server.
client.Connect("smtp.gmail.com", 465, SecurityMode.Implicit);
// Login to the server.
client.Authenticate("test@domain.com", "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);
}
' Create a new instance of the Imap class and download a message.
Using client As New Imap()
' Connect to the server.
client.Connect("imap.gmail.com", 993, SecurityMode.Implicit)
' Login to the server.
client.Authenticate("test@domain.com", "password")
' Download a message to an instance of the MailMessage class.
Dim msg As MailMessage = client.DownloadMailMessage(imapMessageUniqueId)
End Using
' Create a new instance of the Pop3 class and download a message.
Using client As New Pop3()
' Connect to the server.
client.Connect("pop.gmail.com", 995, SecurityMode.Implicit)
' Login to the server.
client.Authenticate("test@domain.com", "password")
' Download the message to an instance of the MailMessage class.
Dim msg As MailMessage = client.DownloadMailMessage(pop3MessageSequenceNumber)
End Using
' Create a new instance of the Smtp class and send an email.
Using client As New Smtp()
' Connect to the server.
client.Connect("smtp.gmail.com", 465, SecurityMode.Implicit)
' Login to the server.
client.Authenticate("test@domain.com", "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)
End Using