欢迎光临
我们一直在努力

邮件发送简单例子-bean文件-JSP教程,Jsp/Servlet

建站超值云服务器,限时71元/月

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();

}

}

}

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 邮件发送简单例子-bean文件-JSP教程,Jsp/Servlet
分享到: 更多 (0)

相关推荐

  • 暂无文章