邮件发送简单例子-bean文件

2016-01-29 12:04 4 1 收藏

邮件发送简单例子-bean文件,邮件发送简单例子-bean文件

【 tulaoshi.com - Java 】

  SimpleSendMessage.java

import java.util.*;

import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class SimpleSendMessage {

public static void main(String[] args) {

// Collect the necessary information to send a simple message
// Make sure to replace the values for host, to, and from with
// valid information.
// host - must be a valid smtp server that you currently have
// access to.
// to - whoever is going to get your email
// from - whoever you want to be. Just remember that many smtp
// servers will validate the domain of the from address
// before allowing the mail to be sent.
String host = "server.myhost.com";
String to = "YourFriend@somewhere.com";
String from = "MeMeMe@myhost.com";
String subject = "JSP Rules!";
String messageText = "I am sending a message using the"
+ " JavaMail API.nI can include any text that I want.";
boolean sessionDebug = false;

// Create some properties and get the default Session.
Properties props = System.getProperties();
props.put("mail.host", host);
props.put("mail.transport.protocol", "smtp");

Session session = Session.getDefaultInstance(props, null);

// Set debug on the Session so we can see what is going on
// Passing false will not echo debug info, and passing true
// will.
session.setDebug(sessionDebug);

try {

// Instantiate a new MimeMessage and fill it with the
// required information.
Message msg = new MimeMessage(session);

msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(messageText);

// Hand the message to the default transport service
// for delivery.
Transport.send(msg);
}
catch (MessagingException mex) {

mex.printStackTrace();
}
}
}
 

来源:http://www.tulaoshi.com/n/20160129/1484522.html

延伸阅读
CREATE OR REPLACE PROCEDURE PROCSENDEMAIL(P_TXT        VARCHAR2,                                     &nb...
标签: PHP
  测试过的环境   win2000/IIS linux/apache win2000 下的 apache 没有成功!不知道为什么!!! <? echo "你会看到这个技术的前景!哈哈!...什么?没看到,刷新一次看看!! 看到了吧!!"; $i = 1;   for($j=0;$j<500;$j++)print(" "); //这一行就是不用刷新页面就能显示的部分...
标签: PHP
  一个简单的自动发送邮件系统     php的另一个强大的特征就是他有能通过html的表单修改变量的能力,通过这些变量,我们可以实现很多任务,包括象:发送wed-based的邮件,把信息输出给屏幕,从数据库中读取和传递数据。下面让我们构建一个小型的自动发送邮件系统,来演示这个能力。     让我们...
标签: ASP
  Click here to copy the Code to your clipboard (Only for IE Users) 'Declare Variables Dim CDONTSObj, MessageBody 'Create the CDONTS object Set CDONTSObj = Server.CreateObject("CDONTS.NewMail") 'To Address CDONTSObj.To = "info@scriptmate.com" 'From Address CDONTSObj.From = "you@yours...
标签: PHP
  一个简单的自动发送邮件系统(三)     这里介绍php和mysql结合起来实用。如何从mysql数据库中提取数据。     好,我们已经成功的完成了我们的要求,很多的数据已经存在了数据库中,现在的问题是,如何查询这些数据,得到有用的结果呢? 在下面的程序中,我们将选择"apple"的...

经验教程

490

收藏

40
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部