一起学习
jeson
下面程序发送邮件消息,它需要三个命令行参数
SMTP Server
From Email Address
To Email Address
例如: java Example smtp.mailserver form@from.com to@to.com
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
public class MailExample
{
public static void main(String args[])
throws Exception
{
String host=args[0];
String from=args[1];
String to=args[2];
//Get system properties
Properties props=System.getProperties();
//Setup mail server
props.put("mail.smtp.host",host);
//Get Session
Session session =Session.getInstance(props,null);
//Define message
MimeMessage message=new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject("Hello JavaMail");
message.setText("Welcome to JavaMail");
//send message
Transport.send(message);
}
}
|
下载本文示例代码
JavaMail中的"Hello World"JavaMail中的"Hello World"JavaMail中的"Hello World"JavaMail中的"Hello World"JavaMail中的"Hello World"JavaMail中的"Hello World"JavaMail中的"Hello World"JavaMail中的"Hello World"JavaMail中的"Hello World"JavaMail中的"Hello World"JavaMail中的"Hello World"JavaMail中的"Hello World"
阅读(123) | 评论(0) | 转发(0) |