⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mail.java

📁 IBM Websphere 工作流MQ Workflow 开发示例
💻 JAVA
字号:
/*BEGIN CMVC */
//*************************************************************************
//
//  Workfile: mqwfupes/src/com/acme/sample/Mail.java, v3-upes, fmv3
//  Last update: 03/11/18 10:34:42
//  SCCS path, id: /home/flowmark/vc/0/5/5/8/s.01 1.1
//
//************************************************************************/
/*END CMVC */
/*BEGIN COPYRIGHT */
//*************************************************************************
//
//  Licensed Materials - Property of IBM
//  WA05 Support Pac - WebSphere MQ Workflow UPES Framework
//  (c) Copyright IBM Corp. 2003
//  US Government Users Restricted Rights - Use, duplication or
//  disclosure restricted by GSA ADP Schedule Contract
//  with IBM Corp.
//
//************************************************************************/
/*END COPYRIGHT */
/*BEGIN DISCLAIMER */
//*************************************************************************
//  DISCLAIMER
//  ----------
//  This material contains programming source code for your consideration.
//  These examples have not been thoroughly tested under all conditions.
//  IBM, therefore, cannot guarantee or imply reliability, serviceability,
//  or function of these programs.
//  ALL PROGRAMS CONTAINED HEREIN ARE PROVIDED TO YOU "AS IS", WITHOUT ANY
//  WARRANTIES (EXPRESS OR IMPLIED) OR SUPPORT WHATSOEVER, INCLUDING BUT
//  NOT LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS
//  FOR A PARTICULAR PURPOSE.
//************************************************************************/
/*END DISCLAIMER */

package com.acme.sample;

import java.util.Date;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

/**
 * A simple Java class which will send an email via JavaMail.
 *
 * @author Robert Junghuber (<a href="mailto:junghub@de.ibm.com">junghub@de.ibm.com</a>)
 * 2.0.2
 *
 */

public class Mail
{
  /**
   * Constructor. Sets up the (hard-coded) SMTP Host. 
   */
  
  public Mail()
  {
    Properties p = new Properties();

    p.put("mail.smtp.host", "mail.ibm.com");

    session = Session.getDefaultInstance(p, null);
  }

  /**
   * 
   * @param fromAddress email address of the sender
   * @param toAddress email address of the receiver
   * @param subject text for the subject line
   * @param body text for the message body 
   * @return Zero, if successful, 1 if an error occurred
   */
  
  public int send(String fromAddress, String toAddress, String subject, String body)
  {
    Message m = new MimeMessage(session);
    
    System.out.println("fromAddress: " + fromAddress);
    System.out.println("toAddress  : " + toAddress);
    System.out.println("subject    : " + subject);
    System.out.println("body       : " + body);
    
    try
    {
      m.setFrom(new InternetAddress(fromAddress));
      m.setRecipients(Message.RecipientType.TO, new InternetAddress[] { new InternetAddress(toAddress) });
      m.setSubject(subject);
      m.setSentDate(new Date());
      m.setText(body);
  
      Transport.send(m);
    
      return 0;
    }
    catch (Exception e) { 
	e.printStackTrace();
	return 1; 
    }
  }
  
  private final Session session;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -