这仅适用于(smtp.office365.com)SMTP.
public int sendEmail(String fromName,String fromAddress,ArrayList toAddressList ,ArrayList ccAddressList,ArrayList bccAddressList,String subject,String message,String SmtpServerIP,String smtpUserName,String smtpPassword, ArrayList<String> attachmentFilePath ){
SMTP_HOST_NAME=SmtpServerIP;
SMTP_AUTH_USER=smtpUserName;
SMTP_AUTH_PWD=smtpPassword;
String emailmultipart="true";
String smtpHost=SmtpServerIP;
//System.out.println("SmtpServerIP"+SmtpServerIP);
System.out.println("fromName :"+fromName+":SmtpServerIP:"+SmtpServerIP+":smtpPassword:"+smtpPassword+":smtpUserName:"+smtpUserName);
boolean debug = false;
Properties props = new Properties();
props.put("mail.smtp.starttls.enable","true");
props.setProperty("mail.transport.protocol", "smtp");
if(smtpHost==null){
return -99;
}
if(smtpHost.length()>0){
//props.put("mail.smtp.host", smtpHost);
props.setProperty("mail.host", smtpHost);
}
else
{
return 1;
}//Error No SmtpHost name Found.
/* if(smtpUserName!=null && smtpUserName.length()>0){
props.setProperty("mail.user", smtpUserName);
}
if(smtpPassword!=null && smtpPassword.length()>0){
props.setProperty("mail.password", smtpPassword);
}*/
Session session=null;
if(smtpUserName!=null && smtpUserName.length()>0&&smtpPassword!=null && smtpPassword.length()>0){
System.out.println("smtpUserName111111111111111"+smtpUserName); …Run Code Online (Sandbox Code Playgroud)