Home  >  Article  >  类库下载  >  Java mail sending, qq and 163 mailboxes send each other, and qq and 163 mailboxes send other mailbox instances

Java mail sending, qq and 163 mailboxes send each other, and qq and 163 mailboxes send other mailbox instances

高洛峰
高洛峰Original
2016-10-29 13:48:172377browse

1. First, you need to import a jar package into your project: mail-1.4.4.jar (to implement qq and 163 mailboxes to send other mailboxes (this case only demonstrates one type))

2. The code is as follows Show

public class TestDemo1 {
    static String SSL_EMAIL = "javax.net.ssl.SSLSocketFactory";

   //需要传的值都在main方法调用的sendmail里传!
    public static void main(String[] args) {
         String s = sendmail(username, pass, from, to, subject, content);
         System.out.println(s);
    }
    /**
     * 
     * @param username 发件人邮件的用户名
     * @param pass 发件人邮件的密码(此密码一定要是授权码   授权码:在发件人邮箱内开启smtp/pop3协议所获得的授权码)
     * @param from 发件人邮箱
     * @param to   收件人邮箱
     * @param subject 邮件标题
     * @param content 邮件内容
     * @return
     */
    public static String sendmail(final String username, final String pass,
            String from, String to, String subject, String content) {
        //Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
        //设置系统参数
        Properties props = System.getProperties();
        props.setProperty("mail.smtp.socketFactory.class", SSL_EMAIL);
        props.setProperty("mail.smtp.socketFactory.fallback", "true");
        props.setProperty("mail.store.protocol", "smtp");
        props.setProperty("mail.smtp.host", "smtp.qq.com");
        //props.setProperty("mail.smtp.port", "465");
        props.setProperty("mail.smtp.socketFactory.port", "465");
        props.put("mail.smtp.auth", "true");
        //创建邮件会话
        Session session = Session.getInstance(props, new Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, pass);
            }
        });
        //创建邮件信息
        Message msg = new MimeMessage(session);
        try {
            msg.setFrom(new InternetAddress(username));
            msg.setRecipients(Message.RecipientType.TO,
                    InternetAddress.parse(to, false));
            msg.setSubject(subject);
            msg.setText(content);
            msg.setSentDate(new Date());
            Transport.send(msg);
            return "1";
        } catch (MessagingException e) {
            return e.getMessage();
        }
    }
}

3. Remember the following points when sending emails:

  (1) The party sending the email must activate the smtp/pop3 protocol!

  (2) The party sending the email must use the authorization code after activation as the password to set it!

  (3) When changing the sender's email type (for example, you used XXX@qq.com at the beginning, and you want to change it to .qq.com, 163 is smtp.163.com

  (4) The following are common error types: the most common ones are 550 DT:SPM and 535 (535 is the wrong information for your sending email party, it may be The authorization code has expired, or the user name may have been written incorrectly)

 •421 HL:REP The sending behavior of this IP is abnormal, there are a large number of receivers that do not exist, and the connection is temporarily prohibited. Please check whether there are any users sending viruses or spam, and check the validity of the sending list;
 •421 HL:ICC The number of concurrent connections for this IP is too large, exceeding NetEase's limit, and the connection is temporarily prohibited. Please check if there are any users sending viruses or spam, and reduce the number of concurrent connections to the IP;
 •421 HL:IFC This IP has sent a large number of letters in a short period of time, exceeding NetEase's limits, and has been temporarily banned from connecting. Please check if there are any users sending viruses or spam, and reduce the frequency of sending;
 •421 HL:MEP The sending behavior of this IP is abnormal, there are a lot of forged sending domain names, and the connection is temporarily prohibited. Please check if any user is sending viruses or spam, and use a real and valid domain name to send it;
 •450 MI:CEL The sender has too many error instructions. Please check the sending program;
 •450 MI: The number of emails sent by DMC on the current connection exceeds the limit. Please reduce the number of emails delivered in each connection;
 •450 MI:CCL The sender sends an excessive number of instructions. Please check the sending program;
 •450 RP:DRC The number of recipients sent by the current connection exceeds the limit. Please control the number of emails delivered per connection;
 •450 RP:CCL The sender sends an excessive number of instructions. Please check the sending procedure;
 •450 DT:RBL The sending IP is located in one or more RBLs. Please refer to http://www.rbls.org/ for relevant information about RBL;
 •450 WM:BLI This IP is not in the list of sending addresses allowed by NetEase;
 •450 WM:BLU This user is not among the sending users allowed by NetEase In the list;
 •451 DT:SPM, please try again. The email body contains spam characteristics or the sending environment lacks standardization, so it is temporarily rejected. Please keep the email queue and resend the email after two minutes. The email content needs to be adjusted or the sending environment needs to be optimized;
 •451 Requested mail action not taken: too much fail authentication There have been too many login failures and the user has been temporarily banned from logging in. Please check the password and account verification settings;
 •451 RP:CEL The sender has too many error instructions. Please check the sending program;
 •451 MI:DMC The number of emails sent by the current connection exceeds the limit. Please control the number of emails delivered in each connection;
 •451 MI:SFQ The number of emails sent by the sender within 15 minutes exceeds the limit, please control the frequency of sending emails;
 •451 RP:QRC The cumulative number of emails sent by the sender in the short term The number of senders exceeds the limit, and the sender is temporarily prohibited from sending letters. Please reduce the frequency of this user sending messages;
 •451 Requested action aborted: local error in processing The system is temporarily faulty, please try sending again later;
 •500 Error: bad syntaxU The syntax of the smtp command sent is incorrect;
 •550 MI The :NHD HELO command is not allowed to be empty;
 •550 MI:IMF The sender's email address is illegal. Please refer to http://www.rfc-editor.org/ for the definition of email specifications;
 •550 MI: SPF The sending IP is not authorized by the SPF of the sending domain. Please refer to http://www.openspf.org/ for the definition of the SPF specification;
 •550 MI:DMA This email is not authorized by the DMARC of the sending domain. Please refer to http://dmarc.org/ for the definition of DMARC specification;
 •550 MI:STC The sender’s number of connections for the day exceeds the limit, and the sender’s emails will no longer be accepted that day. Please control the number of connections;
 •550 RP:FRL NetEase mailbox does not allow anonymous forwarding (Open relay);
 •550 RP:RCL The number of recipients for group sending exceeds the limit, please reduce the number of recipients for each email;
 • 550 RP:TRC The number of recipients accumulated by the sender within the day exceeds the limit, and the sender's emails will no longer be accepted that day. Please reduce the frequency of emails sent by this user;
 •550 DT:SPM The body of the email contains many spam characteristics or the sending environment lacks standardization. It is necessary to adjust the email content or optimize the sending environment;
 •550 Invalid User The requested user does not exist;
 •550 User in blacklist This user is not allowed to send letters to NetEase users;
 •550 User suspended The requested user is disabled or frozen ;
 •550 Requested mail action not taken: too much recipient The number of group messages exceeds the limit;
 •552 Illegal Attachment This type of attachment is not allowed to be sent, including .uu .pif .scr .mim .hqx .bhx .cmd .vbs Attachments ending in .bat .com .vbe .vb .js .wsh, etc.;
 •552 Requested mail action aborted: exceeded mailsize limit The size of the letter sent exceeded the maximum limit allowed to be received by NetEase mailbox;
 •553 Requested action not taken: NULL sender is not allowed The sender is not allowed to be empty, please use the real sender to send;
 •553 Requested action not taken: Local user only SMTP type machines only allow the sender to be the user of this site;
 •553 Requested action not taken: no smtp MX only MX type machines do not allow the sender to be a user of this site;
 •553 authentication is required SMTP requires authentication, please check the client settings;
•554 DT: The content of the email sent by SPM contains unauthorized information or is recognized by the system as spam. Please check if any user sends viruses or spam;
 •554 DT:SUM The envelope sender and letterhead sender do not match;
 •554 IP is rejected, smtp auth error limit exceed The IP has failed verification too many times and has been temporarily Connection prohibited. Please check the verification information settings;
 •554 HL:IHU The sending IP was temporarily suspended due to sending spam or abnormal connection behavior. Please check the historical sending status of the sending IP and whether there are any abnormalities in the sending program;
 •554 HL:IPB This IP is not in NetEase’s allowed sending address list;
 •554 MI:STC The sender’s accumulated emails within the day If the quantity exceeds the limit, letters from this sender will no longer be accepted on that day. Please reduce the frequency of sending emails;
 •554 MI:SPB This user is not in the list of users allowed by NetEase to send emails;
  •554 IP in blacklist This IP is not in the list of sending addresses allowed by NetEase.


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Mybatis common summaryNext article:Mybatis common summary