佳木斯湛栽影视文化发展公司

主頁 > 知識庫 > 郵件發(fā)送簡單例子-bean文件

郵件發(fā)送簡單例子-bean文件

熱門標(biāo)簽:呼叫中心市場需求 銀行業(yè)務(wù) 檢查注冊表項 網(wǎng)站文章發(fā)布 智能手機 鐵路電話系統(tǒng) 服務(wù)器配置 美圖手機
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();
}
}
}

標(biāo)簽:滄州 河南 長治 上海 沈陽 紅河 樂山 新疆

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《郵件發(fā)送簡單例子-bean文件》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    德庆县| 灵台县| 台湾省| 高州市| 阳江市| 玛曲县| 农安县| 北宁市| 乌拉特中旗| 宜良县| 岐山县| 甘洛县| 文山县| 黄石市| 古田县| 峨边| 中山市| 水富县| 建阳市| 洛浦县| 营山县| 淳安县| 新源县| 清新县| 蒲江县| 开鲁县| 台山市| 富川| 开化县| 改则县| 呼和浩特市| 西乌珠穆沁旗| 汶川县| 肥城市| 怀化市| 保康县| 芦溪县| 千阳县| 吐鲁番市| 通河县| 江北区|