Properties properties = System.getProperties();
properties.put("mail.smtp.host","smtp.sina.com.cn");
properties.put("mail.transport.protocol", "smtp");
properties.put("mail.smtp.auth","true");
Session session = Session.getInstance(properties,
new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(strUserName,strPassword);
}
});
try
{
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(strMail));
InternetAddress[] toadd = InternetAddress.parse(strEmailTo);
message.setRecipients(Message.RecipientType.TO,toadd); message.setSubject(strSubject,"Shift_JIS");
message.setText(strFullMailText,"Shift_JIS"); Transport transport = session.getTransport();
message.saveChanges();
transport.send(message,message.getAllRecipients());
transport.close(); }
catch (AddressException e)
{
}
catch (SendFailedException e)
{
}
catch (MessagingException e)
{
}
properties.put("mail.smtp.host","smtp.sina.com.cn");
properties.put("mail.transport.protocol", "smtp");
properties.put("mail.smtp.auth","true");
Session session = Session.getInstance(properties,
new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(strUserName,strPassword);
}
});
try
{
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(strMail));
InternetAddress[] toadd = InternetAddress.parse(strEmailTo);
message.setRecipients(Message.RecipientType.TO,toadd); message.setSubject(strSubject,"Shift_JIS");
message.setText(strFullMailText,"Shift_JIS"); Transport transport = session.getTransport();
message.saveChanges();
transport.send(message,message.getAllRecipients());
transport.close(); }
catch (AddressException e)
{
}
catch (SendFailedException e)
{
}
catch (MessagingException e)
{
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货