Home  >  Q&A  >  body text

用Java写发送邮件的程序,经常被当做垃圾邮件处理怎么解决

 sendMail(String receiver,String content){
       Properties properties=new Properties();
       properties.setProperty("mail.smtp.auth","true");
       properties.setProperty("mail.transport.protocol","smtp");
       properties.setProperty("mail.host","smtp.163.com");
       
       Session session =Session.getInstance(properties,new Authenticator(){
             protected PasswordAuthentication getPasswordAuthentication() {
             return new PasswordAuthentication("*********163.com","*******");
               }
          }
       );
      
      Message message=new MimeMessage(session);
try {
      message.setFrom(new InternetAddress("*********”@163.com"));
    } catch (AddressException e) {
      return "邮箱的登录失败,请检查你的账户密码是否正确!";
    } catch (MessagingException e) {
      return "你的账户异常,请重新发送!";
    }

try {
      message.addRecipients(RecipientType.TO,InternetAddress.parse(receiver));
      message.setSubject("MachineEye");
      message.setText(content);
    } catch (AddressException e1) {
      return "收件人账户信息不正确!";
    } catch (MessagingException e1) {
      return "收件人账户异常!";
    }
    
try {
      Transport.send(message);
    } catch (MessagingException e) {
      return "邮件发送失败";
    }
return "发送成功!";
}
PHPzPHPz2744 days ago711

reply all(3)I'll reply

  • PHP中文网

    PHP中文网2017-04-18 10:50:04

    ....No matter what language you write in, if the legality and authority of your email address are not recognized, if your content is slightly wrong, or if someone reports you, it will easily end up in the spam mailbox.

    reply
    0
  • 迷茫

    迷茫2017-04-18 10:50:04

    First of all, it has nothing to do with language.

    1.. Declare the email address and header information (msg.Headers.Add("X-Mailer", "Microsoft Outlook Express 6.00.2900.2869"); put on the Outlook vest)

    3. In special circumstances, some servers may still treat you as a spam mailbox after you have put on a legal vest, such as NetEase. This is because your email content may contain some sensitive words or illegal information. of.

    reply
    0
  • 阿神

    阿神2017-04-18 10:50:04

    Looking at phpmailer, I remember to set something up, it seems to be some kind of SASL authentication mechanism, but I don’t know anything else

    reply
    0
  • Cancelreply