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

2016-01-29 12:04 3 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();
}
}
}
 

来源:https://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(" "); //这一行就是不用刷新页面就能显示的部分...
标签: 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...
邮箱大师如何发送邮件?   1)首先打开邮箱大师,在右上方点击,在界面输入收件人邮箱,在主题框点击。   2)弹出窗口可以选择添加照片和添加视频或者拍摄,在界面选择要添加的照片,在图片圆点打上勾,点击。   3)返回界面还可以输入文字留言,最后点击即可。
标签: Web开发
本文讲解了一个使用XML技术上传文件的例子,使用该方法没有传统方法中的种种限制。 这个例子讲述了如何使用MSXML3.0和ADO Stream对象来实现这种新的上传方法。好处有很多,比如,不需要专用的上传组件。 引言 为了在HTML网页中获得上传功能,在客户端我们可以使用如下格式的FORM: FORM NAME="myForm" ACTION=...

经验教程

289

收藏

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