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

JSCAPE Secure FTP Server 5.2 Released
06/03/2009 12:04 PM

JSCAPE Web Document Viewer Released
06/03/2009 12:02 PM

JSCAPE Secure FTP Server Plugin for Outlook Released
06/03/2009 10:03 AM

Secure iNet Factory 8.1.0 Released
04/22/2009 09:53 AM

Secure FTP Factory 8.1.0 Released
04/22/2009 08:40 AM

Secure FTP Applet 5.5 Released
04/07/2009 03:00 PM

more...


Tutorials

Enabling Phone Authentication
04/08/2009 11:24 AM

Detecting and Handling Brute Force Password Attacks
01/29/2009 09:44 AM

Creating a Domain
12/15/2008 11:33 AM

Public key authentication with SFTP
10/02/2008 07:59 AM

Formatting MimeMessages using .NET
09/14/2008 04:31 PM

Communicating with an IMAP4 server in .NET
09/14/2008 03:54 PM

more...


Articles

Using custom forms to automate business processes
07/03/2009 08:51 AM

Public key authentication with SFTP
10/02/2008 07:59 AM

Best Practices for Configuring Your FTP Server
06/03/2008 04:47 PM

What is the difference between passive and active FTP?
05/20/2008 09:27 AM

What is the difference between FTP, FTPS and SFTP?
05/19/2008 04:29 PM

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

more...


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.