Send information to the java qq-mail

Qq-mail to send a message through java program.

1, the first step: download mail jar package: javax.mail.jar

  Download: https: //javaee.github.io/javamail/#Latest_News

  

 

2, directly following code

public  static  void SendMessages () {
         the try {
             // Create some properties Properties class for recording mailbox 
            Final Properties The props = new new Properties ();
             // represents SMTP mail must authenticate 
            props.put ( "mail.smtp. auth "," to true " );
             // here to fill in the SMTP server 
            props.put (" mail.smtp.host "," smtp.qq.com " );
             // port number, QQ mailbox gives two ports, here are 587 
            props.put ( "mail.smtp.port", "587" );
             // here to fill in your account 
            props.put ( "mail.user", "qq.com your qq number @" ) ;
            //The password is here said earlier 16 STMP password
             // get password 
            props.put ( "mail.password", "your password" );
             // build licensing information for SMTP authenticate 
            Authenticator Authenticator = new new the Authenticator () { 
                 protected PasswordAuthentication the getPasswordAuthentication () {
                     // user name, password 
                    String props.getProperty the userName = ( "the mail.user" ); 
                    String password = props.getProperty ( "mail.password" );
                     return  new new PasswordAuthentication (the userName, password);
                }
            };
            // environment attribute and authorization information, create a mail session 
            the Session mailSession = Session.getInstance (props, Authenticator);
             // create a mail message 
            the MimeMessage the Message = new new the MimeMessage (mailSession);
             // set the sender 
            InternetAddress form = new new InternetAddress ( props.getProperty ( "mail.user" )); 
            message.setFrom (form); 
 
            // set the recipient's mailbox 
            InternetAddress to = new new InternetAddress ( "the recipient's mailbox qq.com @" ); 
            message.setRecipient (RecipientType .TO, to); 
 
            // set the message subject 
            message.setSubject ( "test Mail");
             // setup message date 
            message.setSentDate ( new new a Date ()); 
            
            // HTML file 
            the StringBuilder SB = new new the StringBuilder (); 
            sb.append ( "<h1 of> text </ h1 of>" );        
             // Set the message the content body 
            message.setContent (sb.toString (), "text / HTML; charset = UTF-8" ); 
 
            // Finally, of course, is to send a message 
            Transport.send (the message); 
            System.out.println ( "successfully sent! " ); 
        } the catch (E, AddressException) { 
            System.out.println ( " transmission failed "+! e.getMessage ());
            e.printStackTrace();
        } catch (MessagingException e) {
            System.out.println("发送失败!"+e.getMessage());
            e.printStackTrace();
        }
    }

3, fill in the code above three main places

  ①: Send e-mail numbers

  ②: Password mailbox number sent (below will explain how to obtain)

  ③: the recipient's mailbox number

4, so that you can send mail to someone else.

  Code Reference: https: //blog.csdn.net/qq_41750725/article/details/83831589

 

5, how to get the sender's password

  ①: Log qq-mail sender - "find accounts
  

  ②: pulled below, find the need to open the service, and then open it to the appropriate service.

  

  ③: After open, you will get to a 16-bit password up.

  ④: specific Reference: https: //jingyan.baidu.com/article/fedf0737af2b4035ac8977ea.html

 

The above method provides qq-mail as an example, other mail is almost the same operation. The following provides a mail server and port numbers for each mailbox

sina.com:
POP3服务器地址:pop3.sina.com.cn(端口:110)
SMTP服务器地址:smtp.sina.com.cn(端口:25) 

sinaVIP:
POP3服务器:pop3.vip.sina.com (端口:110)
SMTP服务器:smtp.vip.sina.com (端口:25)

sohu.com:
POP3服务器地址:pop3.sohu.com(端口:110)
SMTP服务器地址:smtp.sohu.com(端口:25)

126邮箱:
POP3服务器地址:pop.126.com(端口:110)
SMTP服务器地址:smtp.126.com(端口:25)

139邮箱:
POP3服务器地址:POP.139.com(端口:110)
SMTP服务器地址:SMTP.139.com(端口:25)

163.com:
POP3服务器地址:pop.163.com(端口:110)
SMTP服务器地址:smtp.163.com(端口:25)

QQ邮箱 
POP3服务器地址:pop.qq.com(端口:110)
SMTP服务器地址:smtp.qq.com (端口:25)

QQ企业邮箱
POP3服务器地址:pop.exmail.qq.com (SSL启用 端口:995)
SMTP服务器地址:smtp.exmail.qq.com(SSL启用 端口:587/465)

yahoo.com:
POP3服务器地址:pop.mail.yahoo.com
SMTP服务器地址:smtp.mail.yahoo.com

yahoo.com.cn:
POP3服务器地址:pop.mail.yahoo.com.cn(端口:995)
SMTP服务器地址:smtp.mail.yahoo.com.cn(端口:587

HotMail
POP3服务器地址:pop3.live.com (端口:995)
SMTP服务器地址:smtp.live.com (端口:587)

gmail(google.com)
POP3服务器地址:pop.gmail.com(SSL启用 端口:995)
SMTP服务器地址:smtp.gmail.com(SSL启用 端口:587263.net:
POP3服务器地址:pop3.263.net(端口:110)
SMTP服务器地址:smtp.263.net(端口:25263.net.cn:
POP3服务器地址:pop.263.net.cn(端口:110)
SMTP服务器地址:smtp.263.net.cn(端口:25)

x263.net:
POP3服务器地址:pop.x263.net(端口:110)
SMTP服务器地址:smtp.x263.net(端口:25)

21cn.com:
POP3服务器地址:pop.21cn.com(端口:110)
SMTP服务器地址:smtp.21cn.com(端口:25)

Foxmail:
POP3服务器地址:POP.foxmail.com(端口:110)
SMTP服务器地址:SMTP.foxmail.com(端口:25)

china.com:
POP3服务器地址:pop.china.com(端口:110)
SMTP服务器地址:smtp.china.com(端口:25)

tom.com:
POP3服务器地址:pop.tom.com(端口:110)
SMTP服务器地址:smtp.tom.com(端口:25)

etang.com:
POP3服务器地址:pop.etang.com
SMTP服务器地址:smtp.etang.com

具体参考:https://blog.csdn.net/smok56888/article/details/50070453#

Guess you like

Origin www.cnblogs.com/masha2017/p/11122879.html