首页 > 学院 > 开发设计 > 正文

JavaMail快速入门-2

2019-11-18 16:20:41
字体:
来源:转载
供稿:网友

  通过SMTP发送email

  第一个例子告诉你怎样通过SMTP发送一个基本的email消息。在下面,你将找到SimpleSender类,它从命令行读取你的消息,然后调用一个单独的方法send(…)来发送它们:

package com.lotontech.mail;

import javax.mail.*;

import javax.mail.internet.*;

import java.util.*;

/**

* A simple email sender class.

*/

public class SimpleSender

{

 /**

  * Main method to send a message given on the command line.

 */

 public static void main(String args[])

 {

  try

  {

   String smtpServer=args[0];

   String to=args[1];

   String from=args[2];

   String subject=args[3];

   String body=args[4];

   send(smtpServer, to, from, subject, body);

  }

  catch (Exception ex)

  {

   System.out.PRintln("Usage: java com.lotontech.mail.SimpleSender"

       +" smtpServer toAddress fromAddress subjectText bodyText");

  }

  System.exit(0);

 }

(出处:http://www.VeVb.com)



发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表