java smtp, smtp ssl, email ssl
Home Search Knowledge Base Support

Support

Click here for access to live sales support.

For technical support please submit a ticket to the Help Desk.

 

Java and .NET Help

iPod shuffle offer

For a limited time get the newly re-designed iPod shuffle free with qualifying purchase.

Click for details.


News

Secure iNet Factory 8.0 Released
04/04/2008 02:24 PM

Updates to Email Factory for .NET and Secure iNet Factory
03/29/2008 04:06 PM

JSCAPE Secure FTP Server 3.9 Preview
03/14/2008 12:19 PM

AnyClient Service and Application Launched
03/12/2008 03:41 PM

JSCAPE Secure FTP Server 3.8 Released
02/12/2008 10:50 AM


Tutorials

Email Validation with Java
04/15/2008 02:04 PM

Sending HTML Based Email Using Java
03/11/2008 02:47 PM

Secure FTP Using Java and FTPS (FTP over SSL)
03/10/2008 04:08 PM

FTP Directory Listing Using Java
03/10/2008 03:57 PM

Sending Email Using Java
03/09/2008 03:43 PM

SSH Using Java
03/09/2008 02:53 PM


Articles

DMZ File Transfer Streaming
03/28/2008 11:57 AM

Phishing looks to FTP to distribute malware
03/13/2008 05:14 PM

Ad Hoc File Transfer Explained
03/13/2008 09:16 AM

Password Policies Made Easy
03/12/2008 03:03 PM


Feedback

Request a feature or component

Request a Java or .NET component


 

Overview

The free Google email service Gmail offers over 2GB of storage space prompting many people to signup for accounts. In addition to providing POP access, Gmail also provides remote SMTP access allowing you to send mail using the Gmail SMTP server.

In order to prevent spam and provide increased security the Gmail SMTP server requires that you connect using SMTP SSL and login using your account credentials prior to sending any mail.

The purpose of this article is to demonstrate how to securely connect to the Gmail SMTP server and send mail using the Java com.jscape.inet.smtpssl.SmtpSsl class found in Secure iNet Factory.

The procedures in this article may also apply to other SMTP servers which provide secure SSL/TLS access.

For a tutorial on retrieving email from Gmail see Retrieving email securely from Gmail using POP SSL.

Prerequisites

  1. A Gmail account. As of this writing this service is still in beta. If you do not have an account you must get invited to open an account from someone who already has one.
  2. JDK 1.2.2 or above and Secure iNet Factory

Note

If using a JDK prior to JDK 1.4 then you must download and install the JSSE (Java Secure Socket Extensions). Instructions for doing this are provided in the Secure iNet Factory User Guide.

Example

01 import com.jscape.inet.smtpssl.*;
02 import com.jscape.inet.email.*;
03 
04 public class SmtpGmail {
05   
06   public static void main(String[] args) {
07     SmtpSsl smtp = null;
08     
09     // gmail username - CHANGE THIS
10     String username = "username@gmail.com";
11     
12     // gmail password - CHANGE THIS
13     String password = "password";
14     
15     // address to send mail to - CHANGE THIS
16     String to = "user@domain.com";
17     try {      
18       // create a new SmtpSsl instance connecting securely via port 465 using implicit SSL
19       smtp = new SmtpSsl("smtp.gmail.com",465);
20       
21       // establish secure connection
22       smtp.connect();
23       
24       // login using gmail account details
25       smtp.login(username,password);
26       
27       // create new email message
28       EmailMessage message = new EmailMessage();
29       message.setTo(to);
30       message.setFrom(username);
31       message.setSubject("Sending email via Gmail SMTP");
32       message.setBody("This is the body of the message");
33       
34       // send message
35       smtp.send(message);
36       
37       // disconnect      
38       smtp.disconnect();      
39     catch(Exception e) {
40       // capture any exception and print to console
41       e.printStackTrace();
42     
43   }
44 }
  1. Lines 1-2. Import necessary classes.
  2. Lines 7-16. Define SmtpSsl member variable, Gmail account information and address to send message to.
  3. Line 19. Create new SmtpSsl instance.
  4. Line 22. Establish secure connection to Gmail SMTP server
  5. Line 25. Login using Gmail account credentials.
  6. Lines 28-32. Create email message.
  7. Line 35. Send message.
  8. Line 38. Disconnect from Gmail SMTP server.

Summary

In this article you learned how to securely send email via the Gmail SMTP server using the secure SMTP classes provided in Secure iNet Factory.

The procedures in this article may also apply to other SMTP servers which provide secure SSL/TLS access.