Java SMTP Component - javamail, SMTP Class, SMTP Bean, SMTP Object, SMTP Client, SMTP Control
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 4.1 Released
08/01/2008 07:36 AM

JSCAPE is Hiring
06/27/2008 02:34 PM

JSCAPE Secure FTP Server 4.0 Released
06/20/2008 08:53 AM

Secure iNet Factory 8.0.3 Released
06/11/2008 08:20 AM

Community forums launched
06/08/2008 06:09 AM

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

more...


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

more...


Articles

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

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

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

more...


Feedback

Request a feature or component

Request a Java or .NET component


 

Java SMTP Component

The SMTP component provides an easy to use API for communicating with SMTP servers and sending e-mail. Written using 100% Java and delivered as a Java Bean makes the SMTP component usable in a wide variety of IDE and platform configurations. Download Secure iNet Factory Evaluation

Features

  • File attachment support - The SMTP component provides a simple API for adding one or more attachments to a e-mail message. Using this API one can easily add one or more attachments from a file or URL.
  • Bulk mail support - For targeted mail campaigns built in Bcc: (blind carbon copy) support and the ability to define recipients from the contents of a file provide an easy API for delivering bulk e-mail
  • HTML message support - For e-mail clients capable of rendering HTML, this feature allows one to send rich-text e-mail to recipients in the form of a web page.
  • E-mail. address validation - The SMTP component supports all valid e-mail address formats specified in RFC 822. SMTP and EmailAddress components offer syntax validation of address, prior to sending e-mail message. This capability reduces network traffic from bounced e-mail messages and provides a way of systematically identifying invalid e-mail addresses.
  • User authentication - Methods to support username/password authentication for SMTP servers which require authentication to prevent unauthorized SMTP relay.
  • Message priority support - For e-mail clients which support message priorities, the SMTP component allows prioritization of an e-mail message. A message with "highest" priority would potentially give the message higher visibility in a recipients mailbox.
  • Header management - Easily define SMTP e-mail header values for submission with a e-mail message. An example might be to set the X-Mailer header typically used to define the client software responsible for generating the mail message.

Code Example

The following code example demonstrates how to send an e-mail along with an attachment using the SMTP component.

/*
 * @(#)SmtpAttachmentExample.java
 *
 * Copyright (c) 2001-2002 JScape
 * 1147 S. 53rd Pl., Mesa, Arizona, 85206, U.S.A.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * JScape. ("Confidential Information").  You shall not disclose such
 * Confidential Information and shall use it only in accordance with
 * the terms of the license agreement you entered into with JScape.
 */

import com.jscape.inet.smtp.*;
import com.jscape.inet.mime.*;
import com.jscape.inet.email.*;
import java.io.*;

public class SmtpAttachmentExample extends SmtpAdapter {
    public void sendMessage(String hostname, String to, String from, String subject, String body, String attachmentthrows SmtpException, 
    IOException, MimeException {
      
      // create new Smtp instance
        Smtp smtp = new Smtp(hostname);
        
        // enable debugging
        smtp.setDebug(true);
        
        // register this class to capture SMTP related events
        smtp.addSmtpListener(this);
        
        // connect to SMTP server
        smtp.connect();
        
        // create email message
        EmailMessage email = new EmailMessage();
        email.setTo(to);
        email.setFrom(from);
        email.setSubject(subject);
        email.setBody(body);
        
        // add attachment to email message
        email.addAttachment(new Attachment(new File(attachment)));
        
        // send email message
        smtp.send(email);
        
        // disconnect from SMTP server
        smtp.disconnect();
    }
    
    // capture connect event
    public void connected(SmtpConnectedEvent evt) {
        System.out.println("Connected to SMTP server: " + evt.getHostname());
    }
    
    // capture disconnect event
    public void disconnected(SmtpDisconnectedEvent evt) {
        System.out.println("Disconnected from SMTP server: " + evt.getHostname());
    }
    
    public static void main(String[] args) {
        String hostname;
        String to;
        String from;
        String subject;
        String body;
        String attach;
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            System.out.print("Enter SMTP hostname (e.g. mail.domain.com): ");
            hostname = reader.readLine();
            System.out.print("Enter To address (e.g. recipient@domain.com): ");
            to = reader.readLine();
            System.out.print("Enter From address (e.g. sender@domain.com): ");
            from = reader.readLine();
            subject = "iNet Factory Attachment Example";
            body = "see attached image";
            attach = "image.gif";
            SmtpAttachmentExample example = new SmtpAttachmentExample();
            example.sendMessage(hostname,to,from,subject,body,attach);
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }
}