Send mail in javax.mail without authentication

后端 未结 2 516
难免孤独
难免孤独 2020-12-09 08:39

I am using javax.mail to send mails in Java. Now that a part of the concept of my project changed I have to send a mail without authentication. I will have to change my crea

相关标签:
2条回答
  • 2020-12-09 08:54
    private void createSession() {
      properties.put("mail.smtp.auth",false);
      properties.put("mail.smtp.starttls.enable","true");
      properties.put("mail.smtp.port","587");
      properties.put("mail.smtp.host","smtp.gmail.com");
      properties.put("mail.smtp.username","username(emailid")");
      properties.put("mail.smtp.password","password(mail password)");
    
      Session session=Session.getDefaultInstance(properties,null);
    
    }
    
    0 讨论(0)
  • 2020-12-09 09:10
    private void createSession() {
        properties.put("mail.smtp.auth", "false");
         //Put below to false, if no https is needed
        properties.put("mail.smtp.starttls.enable", "true");
        properties.put("mail.smtp.host", server);
        properties.put("mail.smtp.port", port);
    
        session = Session.getInstance(properties);
    }
    

    I think, this would suffice.

    0 讨论(0)
提交回复
热议问题