Question about SMTP verification of connections sent by javamail

Source: Internet
Author: User
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 ("processing ing 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 =" + );
InternetAddress fromAddress = new InternetAddress (from );
InternetAddress [] toAddresss = new InternetAddress [3];
ToAddresss [0] = new InternetAddress ("jcren@163.com ");
ToAddresss [1] = new InternetAddress ("xxxxx@163.com ");
ToAddresss [2] = new InternetAddress ("ccccc@163.com ");
Int I = 0;
While (I <toAddresss. length ){
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 = "jcren@163.com ";
String to = "jcren@163.com ";

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.