本文整理匯總了Java中javax.mail.internet.MimeMessage.setRecipient方法的典型用法代碼示例。如果您正苦於以下問題:Java MimeMessage.setRecipient方法的具體用法?Java MimeMessage.setRecipient怎麽用?Java MimeMessage.setRecipient使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.mail.internet.MimeMessage
的用法示例。
在下文中一共展示了MimeMessage.setRecipient方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createSimpleMail
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
/**
* @Method: createSimpleMail
* @Description: ����һ��ֻ�����ı����ݵ��ʼ�
* @param session
* @return
* @throws Exception
*/
public static MimeMessage createSimpleMail(String subject, String content) throws Exception {
//�����ʼ�����
MimeMessage message = new MimeMessage(session);
//ָ���ʼ��ķ�����
message.setFrom(new InternetAddress(username));
if(recipients.contains(";")){
List<InternetAddress> list = new ArrayList<InternetAddress>();
String []median=recipients.split(";");
for(int i=0;i<median.length;i++){
list.add(new InternetAddress(median[i]));
}
InternetAddress[] address =list.toArray(new InternetAddress[list.size()]);
message.setRecipients(Message.RecipientType.TO,address);
}else{
message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
}
//�ʼ��ı���
message.setSubject(subject);
//�ʼ����ı�����
message.setContent(content, "text/html;charset=UTF-8");
//���ش����õ��ʼ�����
return message;
}
示例2: createCodeMessage
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
/**
* 創建一封郵件
*
* @param session 和服務器交互的會話
* @param sendMail 發件人郵箱
* @param receiveMail 收件人郵箱
* @return
* @throws Exception
*/
private MimeMessage createCodeMessage(Session session, String sendMail, String receiveMail) throws MessagingException, UnsupportedEncodingException {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(sendMail, "吃在華科", "UTF-8"));
message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(receiveMail, this.name, "UTF-8"));
message.setSubject("吃在華科郵件注冊驗證碼", "UTF-8");
String content = this.name + ",你好, 您的驗證碼如下<br/>" + getCode() + "<p> 您不需要回複這封郵件。<p/>";
message.setContent(content, "text/html;charset=UTF-8");
message.setSentDate(new Date());
message.saveChanges();
return message;
}
示例3: buildEmailMessage
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
private Message buildEmailMessage(EmailInfo emailInfo)
throws AddressException, MessagingException, UnsupportedEncodingException {
MimeMessage message = new MimeMessage(this.session);
message.setFrom(new InternetAddress(emailInfo.getFrom(), "網頁更新訂閱係統", "UTF-8"));
message.setRecipient(Message.RecipientType.TO, new InternetAddress(emailInfo.getTo()));
Multipart multipart = new MimeMultipart();
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent(emailInfo.getContent(), "text/html;charset=UTF-8");
multipart.addBodyPart(messageBodyPart);
message.setContent(multipart);
message.setSubject(emailInfo.getTitle());
message.saveChanges();
return message;
}
示例4: createMimeMessage
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
/**
* 創建一封隻包含文本的簡單郵件
*
* @param session
* 和服務器交互的會話
* @param sendMail
* 發件人郵箱
* @param receiveMail
* 收件人郵箱
* @return
* @throws Exception
*/
public static MimeMessage createMimeMessage(Session session, String sendMail, String receiveMail, String username,String pwd)
throws Exception {
// 1. 創建一封郵件
MimeMessage message = new MimeMessage(session);
// 2. From: 發件人(昵稱有廣告嫌疑,避免被郵件服務器誤認為是濫發廣告以至返回失敗,請修改昵稱)
message.setFrom(new InternetAddress(sendMail, "Mircle", "UTF-8"));
// 3. To: 收件人(可以增加多個收件人、抄送、密送)
message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(receiveMail, "", "UTF-8"));
// 4. Subject: 郵件主題(標題有廣告嫌疑,避免被郵件服務器誤認為是濫發廣告以至返回失敗,請修改標題)
message.setSubject(subject, "UTF-8");
// 5. Content: 郵件正文(可以使用html標簽)(內容有廣告嫌疑,避免被郵件服務器誤認為是濫發廣告以至返回失敗,請修改發送內容)
message.setContent(getContent(username,pwd), "text/html;charset=UTF-8");
// 6. 設置發件時間
message.setSentDate(new Date());
// 7. 保存設置
message.saveChanges();
return message;
}
示例5: sendAccountActivateEmail
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
public static void sendAccountActivateEmail(String email, String uuid, int userId) {
Session session;
try {
session = getSession();
MimeMessage message = new MimeMessage(session);
message.setSubject("������֤��");
message.setSentDate(new Date());
message.setFrom(new InternetAddress(FROM));
message.setRecipient(RecipientType.TO, new InternetAddress(email));
message.setContent("�����û�"+userId+":������֤��Ϊ��"+uuid,
"text/html;charset=utf-8");
message.saveChanges();
Transport.send(message);
} catch (Exception e) {
e.printStackTrace();
}
}
示例6: createFeedBackMsg
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
/**
* 創建一封反饋郵件
* @param session
* @param sendMail
* @param detail
* @return
*/
private MimeMessage createFeedBackMsg(Session session, String sendMail, String detail) throws UnsupportedEncodingException, MessagingException {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(sendMail, "吃在華科", "UTF-8"));
message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress("[email protected]", this.name, "UTF-8"));
message.setSubject("吃在華科用戶反饋", "UTF-8");
String content = UserStatus.getUserStatus().getName()+"\n"+detail;
message.setContent(content, "text/html;charset=UTF-8");
message.setSentDate(new Date());
message.saveChanges();
return message;
}
示例7: sendMail
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
/**
* Sends email.
*
* @throws MessagingException
* message exception
*/
private void sendMail() throws MessagingException {
/*
* Properties used to construct a email sending connection protocal.
*/
final Properties props = new Properties();
props.put("mail.smtp.host", MAIL_HOST);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
final Authenticator auth = new SMTPAuthenticator();
final MimeMessage msg = new MimeMessage(Session.getDefaultInstance(props, auth));
msg.setFrom(new InternetAddress(from));
msg.setRecipient(RecipientType.TO, new InternetAddress(to));
msg.setSubject(subject);
msg.setText(message);
Transport.send(msg);
}
示例8: report
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
public void report(UserSetting userSetting, SearchResult searchResult, int resultState) {
if(! (boolean)config.get("enableMailReport"))
return;
final Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.host", "smtp.163.com");
props.put("mail.user", config.get("fromEmailUser"));
props.put("mail.password", config.get("fromEmailPassword"));
// 構建授權信息,用於進行SMTP進行身份驗證
Authenticator authenticator = new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(props.getProperty("mail.user"), props.getProperty("mail.password"));
}
};
Session mailSession = Session.getInstance(props, authenticator);
try {
MimeMessage message = new MimeMessage(mailSession);
message.setFrom(new InternetAddress(props.getProperty("mail.user")));
message.setRecipient(RecipientType.TO, new InternetAddress(config.get("toEmailUser").toString()));
message.setSubject("PTE助手通知");
String content = String.format("賬號 %s 已搜索到可用約會: 時間=%s, 地點=%s",
userSetting.user.username, CalendarUtils.chinese(searchResult.apptTime), searchResult.testCenter);
if(resultState > -1) {
content += "<br>";
content += resultState == 1 ? "並報名成功" : "但報名失敗";
}
message.setContent(content, "text/html;charset=UTF-8");
Transport.send(message);
} catch (MessagingException e) {
e.printStackTrace();
}
}
示例9: test
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
public void test() throws Exception {
Properties props = System.getProperties();
props.put("mail.transport.protocol", "smtps");
props.put("mail.smtp.port", PORT);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.starttls.required", "true");
Session session = Session.getInstance(props);
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(FROM));
msg.setRecipient(Message.RecipientType.TO, new InternetAddress(TO));
msg.setSubject(SUBJECT);
msg.setContent(BODY, "text/plain");
Transport transport = session.getTransport();
try {
transport.connect(HOST, SMTP_USERNAME, SMTP_PASSWORD);
transport.sendMessage(msg, msg.getAllRecipients());
} finally {
transport.close();
}
}
示例10: createAttachMail
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
/**
* @Method: createAttachMail
* @Description: ����һ����������ʼ�
* @param session
* @return
* @throws Exception
*/
public static MimeMessage createAttachMail(String subject, String content, String filePath) throws Exception{
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(username));
if(recipients.contains(";")){
List<InternetAddress> list = new ArrayList<InternetAddress>();
String []median=recipients.split(";");
for(int i=0;i<median.length;i++){
list.add(new InternetAddress(median[i]));
}
InternetAddress[] address =list.toArray(new InternetAddress[list.size()]);
message.setRecipients(Message.RecipientType.TO,address);
}else{
message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
}
message.setSubject(subject);
MimeBodyPart text = new MimeBodyPart();
text.setContent(content, "text/html;charset=UTF-8");
MimeBodyPart attach = new MimeBodyPart();
DataHandler dh = new DataHandler(new FileDataSource(filePath));
attach.setDataHandler(dh);
attach.setFileName(dh.getName());
MimeMultipart mp = new MimeMultipart();
mp.addBodyPart(text);
mp.addBodyPart(attach);
mp.setSubType("mixed");
message.setContent(mp);
message.saveChanges();
return message;
}
示例11: createImageMail
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
/**
* @Method: createImageMail
* @Description: ����һ���ʼ����Ĵ�ͼƬ���ʼ�
* @param session
* @return
* @throws Exception
*/
public static MimeMessage createImageMail(String subject, String content, String imagePath) throws Exception {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(username));
if(recipients.contains(";")){
List<InternetAddress> list = new ArrayList<InternetAddress>();
String []median=recipients.split(";");
for(int i=0;i<median.length;i++){
list.add(new InternetAddress(median[i]));
}
InternetAddress[] address =list.toArray(new InternetAddress[list.size()]);
message.setRecipients(Message.RecipientType.TO,address);
}else{
message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
}
message.setSubject(subject);
MimeBodyPart text = new MimeBodyPart();
text.setContent(content, "text/html;charset=UTF-8");
MimeBodyPart image = new MimeBodyPart();
DataHandler dh = new DataHandler(new FileDataSource(imagePath));
image.setDataHandler(dh);
image.setContentID("xxx.jpg");
MimeMultipart mm = new MimeMultipart();
mm.addBodyPart(text);
mm.addBodyPart(image);
mm.setSubType("related");
message.setContent(mm);
message.saveChanges();
return message;
}
示例12: createMixedMail
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
/**
* @Method: createMixedMail
* @Description: ����һ��������ʹ�ͼƬ���ʼ�
* @param session
* @return
* @throws Exception
*/
public static MimeMessage createMixedMail(String subject, String content, String imagePath, String filePath) throws Exception {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(username));
if(recipients.contains(";")){
List<InternetAddress> list = new ArrayList<InternetAddress>();
String []median=recipients.split(";");
for(int i=0;i<median.length;i++){
list.add(new InternetAddress(median[i]));
}
InternetAddress[] address =list.toArray(new InternetAddress[list.size()]);
message.setRecipients(Message.RecipientType.TO,address);
}else{
message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
}
message.setSubject(subject);
MimeBodyPart text = new MimeBodyPart();
text.setContent(content,"text/html;charset=UTF-8");
MimeBodyPart image = new MimeBodyPart();
image.setDataHandler(new DataHandler(new FileDataSource(imagePath)));
image.setContentID("aaa.jpg");
MimeBodyPart attach = new MimeBodyPart();
DataHandler dh = new DataHandler(new FileDataSource(filePath));
attach.setDataHandler(dh);
attach.setFileName(dh.getName());
MimeMultipart mp = new MimeMultipart();
mp.addBodyPart(text);
mp.addBodyPart(image);
mp.setSubType("related");
MimeBodyPart bodyContent = new MimeBodyPart();
bodyContent.setContent(mp);
message.saveChanges();
return message;
}
示例13: createMimeMessage
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
private static MimeMessage createMimeMessage(MessageBean msgBean, String mimeSubtype, Session session) throws MessagingException {
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(msgBean.getFrom()));
msg.setRecipient(Message.RecipientType.TO, new InternetAddress(msgBean.getTo()));
msg.setSubject(msgBean.getSubject());
msg.setText(msgBean.getContent(), Charset.defaultCharset().name(), mimeSubtype);
return msg;
}
示例14: send
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
public void send() throws Exception{
if(this.mail.getContentType() == null){
this.mail.setContentType(MailContentTypeEnum.HTML.getValue());
}
if(null == this.mail.getContent() || "".equals(this.mail.getContent())){
throw new Exception("郵件內容沒有設置");
}
if(null == this.mail.getTitle()|| "".equals(this.mail.getTitle())){
throw new Exception("郵件標題沒有設置");
}
if(null == this.mail.getSendAddress()|| this.mail.getSendAddress().isEmpty()){
throw new Exception("郵件發送地址沒有設置");
}
final PropertiesUtil util = new PropertiesUtil("mail");
//設置郵件服務器登陸信息
final Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.host", util.getValue("mail.smtp.service"));
props.put("mail.smtp.port", util.getValue("mail.smtp.port"));
props.put("mail.user", util.getValue("mail.from.address"));
props.put("mail.password", util.getValue("mail.from.smtp.pwd"));
// 構建授權信息,用於進行SMTP進行身份驗證
Authenticator authenticator = new Authenticator(){
protected PasswordAuthentication getPasswordAuthentication() {
// 用戶名、密碼
String userName = props.getProperty("mail.user");
String password = props.getProperty("mail.password");
return new PasswordAuthentication(userName, password);
}
};
// 使用環境屬性和授權信息,創建郵件會話
Session mailSession = Session.getInstance(props, authenticator);
// 創建郵件消息
MimeMessage message = new MimeMessage(mailSession);
// 設置發件人昵稱
String nickName = MimeUtility.encodeText(util.getValue("mail.from.nickname"));
InternetAddress form = new InternetAddress(nickName + " <" + props.getProperty("mail.user") + ">");
message.setFrom(form);
// 設置郵件標題
message.setSubject(mail.getTitle());
//html發送郵件
if(mail.getContentType().equals(MailContentTypeEnum.HTML.getValue())) {
// 設置郵件內容
message.setContent(mail.getContent(), mail.getContentType());
}
//文本發送郵件
else if(mail.getContentType().equals(MailContentTypeEnum.TEXT.getValue())){
// 設置郵件內容
message.setText(mail.getContent());
}
//發送郵箱地址
List<String> targets = mail.getSendAddress();
for(int i = 0;i < targets.size();i++){
try {
// 設置收件人的郵箱
InternetAddress to = new InternetAddress(targets.get(i));
message.setRecipient(Message.RecipientType.TO, to);
// 最後當然就是發送郵件啦
Transport.send(message);
}catch (Exception e)
{
e.printStackTrace();
}
}
}
示例15: createMimeMessage
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
private static MimeMessage createMimeMessage(Session session, String sendMail,
String receiveMail, String password) throws Exception {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(sendMail, "易購房", "UTF-8"));
message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(receiveMail, "親愛的用戶", "UTF-8"));
// 4. Subject: 主題
message.setSubject("找回密碼", "UTF-8");
// 5. Content: 內容
message.setContent("您好,以下為您的密碼,請及時修改~\n" + "密碼:" + password, "text/html;charset=UTF-8");
message.setSentDate(new Date());
message.saveChanges();
return message;
}