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

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

时间: 2024-07-28 20:18:32

邮件发送简单例子-bean文件的相关文章

邮件发送简单例子-bean文件_JSP编程

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 mes

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

js MailExample.jsp <html> <head> <title>JSP JavaMail Example </title> </head> <body> <%@ page import="java.util.*" %> <%@ page import="javax.mail.*" %> <%@ page import="javax.mail

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

<html> <head> <title>JavaMail Form</title> </head> <body> <form action="/purejsp/MailExample.jsp" method="post"> <table cellspacing="2" cellpadding="2" border="1&quo

邮件发送简单例子-html文件_JSP编程

<html><head><title>JavaMail Form</title></head> <body><form action="/purejsp/MailExample.jsp" method="post"><table cellspacing="2" cellpadding="2" border="1">

邮件发送简单例子-jsp文件_JSP编程

MailExample.jsp <html><head><title>JSP JavaMail Example </title></head> <body> <%@ page import="java.util.*" %><%@ page import="javax.mail.*" %><%@ page import="javax.mail.interne

WordPress网站实现邮件发送功能例子

windows主机是无法支持mail()函数的,所以无法使用WordPress自带的邮箱服务,而发送邮件的功能对于一个网站来说是必不可少的,对于使用WordPress建站的站长来说,除了可以使用主机邮箱功能发送邮件外,也可以用WP的插件或者直接修改WP的代码在WP网站中实现邮件发送功能. 下面我们就来讨论下用WP的SMTP插件和修改WP代码的两种实现邮件发送功能的方法. 1.使用WP的SMTP插件实现邮件功能 WP 的SMTP插件是国人制作的,设置界面非常简单,是一款全中文的的插件. WP SM

SMTP协议-PHP的邮件发送程序例子

classZSMailBox{var$fpSocket;var$strLog;var$strSMTPServer;var$strSMTPPort;var$strFrom;var$strTo;functionZSMailBox(){$this->strLog="";$this->strSMTPPort="25";$this->strFrom="";$this->strTo="";}functionDoCo

PHP实现发送邮件的方法(基于简单邮件发送类)_php技巧

本文实例讲述了PHP实现发送邮件的方法.分享给大家供大家参考,具体如下: 邮件发送类 <?php /*邮件发送类 *功能:使用smtp服务器发送邮件 */ class smtp { /* 全局变量 */ var $smtp_port; var $time_out; var $host_name; var $log_file; var $relay_host; var $debug; var $auth; var $user; var $pass; var $sock; /* 构造函数 */ fu

简单讲解phpmailer邮件发送例子(带源码下载地址)

我顶PHPMailer ,就如它的名字一样,是一个使用 PHP 编写的邮件发送类,同时,PHPMailer 也是一个功能强大的类. 官方网站:http://phpmailer.codeworxtech.com/ DOWNLOAD:http://code.google.com/a/apache-extras.org/p/phpmailer/ PHPMailer 的主要特点有: 1.在邮件中包含多个 TO.CC.BCC 和 REPLY-TO. 2.平台应用广泛,支持的 smtp 服务器包括 Send