最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
javamail发信的连接SMTP验证的问题
时间:2022-07-02 18:09:59 编辑:袖梨 来源:一聚教程网
MailBean.java
package fastfox.util;
import java.util.*;
import java.text.SimpleDateFormat;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.io.*;
public class MailBean {
public static void sendMessage(String smtpHost,String from,String to,String subject,String messageText)throws MessagingException{
System.out.println("Configuring mail session for:"+smtpHost);
SmtpAuth sa=new SmtpAuth();
sa.getuserinfo("jcren","mypassword");
java.util.Properties props=new java.util.Properties();
props.put("mail.smtp.auth","true");
props.put("mail.smtp.host",smtpHost);
System.out.println("Constructing message- from="+from+" to="+to);
InternetAddress fromAddress=new InternetAddress(from);
InternetAddress[] toAddresss=new InternetAddress[3];
toAddresss[0]=new InternetAddress("[email protected]");
toAddresss[1]=new InternetAddress("[email protected]");
toAddresss[2]=new InternetAddress("[email protected]");
int i=0;
while(i Session mailSession=Session.getDefaultInstance(props,sa);
MimeMessage testMessage=new MimeMessage(mailSession);
testMessage.setFrom(fromAddress);
testMessage.addRecipient(javax.mail.Message.RecipientType.TO,toAddresss[i]);
testMessage.setSentDate(new java.util.Date());
testMessage.setSubject(subject);
testMessage.setText(messageText);
System.out.println("Message constructed");
Transport.send(testMessage);
System.out.println("Message sent!");
i++;
}
}
public static void main(String[] args){
String smtpHost="smtp.163.com";
String from="[email protected]";
String to="[email protected]";
package fastfox.util;
import java.util.*;
import java.text.SimpleDateFormat;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.io.*;
public class MailBean {
public static void sendMessage(String smtpHost,String from,String to,String subject,String messageText)throws MessagingException{
System.out.println("Configuring mail session for:"+smtpHost);
SmtpAuth sa=new SmtpAuth();
sa.getuserinfo("jcren","mypassword");
java.util.Properties props=new java.util.Properties();
props.put("mail.smtp.auth","true");
props.put("mail.smtp.host",smtpHost);
System.out.println("Constructing message- from="+from+" to="+to);
InternetAddress fromAddress=new InternetAddress(from);
InternetAddress[] toAddresss=new InternetAddress[3];
toAddresss[0]=new InternetAddress("[email protected]");
toAddresss[1]=new InternetAddress("[email protected]");
toAddresss[2]=new InternetAddress("[email protected]");
int i=0;
while(i
MimeMessage testMessage=new MimeMessage(mailSession);
testMessage.setFrom(fromAddress);
testMessage.addRecipient(javax.mail.Message.RecipientType.TO,toAddresss[i]);
testMessage.setSentDate(new java.util.Date());
testMessage.setSubject(subject);
testMessage.setText(messageText);
System.out.println("Message constructed");
Transport.send(testMessage);
System.out.println("Message sent!");
i++;
}
}
public static void main(String[] args){
String smtpHost="smtp.163.com";
String from="[email protected]";
String to="[email protected]";
相关文章
- 比特币交易所app下载高盛 虚拟货币app 04-22
- 数字货币平台|美国比特币交易平台 04-22
- LTC莱特币合约交易平台 莱特币LTC永续合约怎么玩? 04-22
- QuickSwap下载_QuickSwap安卓下载v6.3.1免费最新版本下载 04-22
- fil今日行情_fil币价格最新消息 04-22
- 以太币钱包sc-以太币钱包如何使用 04-22