Must issue a STARTTLS command first. Sending email with Java and Google Apps

前端 未结 6 2037
傲寒
傲寒 2020-11-30 05:56

I am trying to use Bill the Lizard\'s code to send an email using Google Apps. I am getting this error:

Exception in thread \"main\" javax.mail.SendFailedEx         


        
6条回答
  •  长情又很酷
    2020-11-30 06:30

    Set the following tags. It will work.

    props.put("mail.smtp.user","username"); 
    props.put("mail.smtp.host", "smtp.gmail.com"); 
    props.put("mail.smtp.port", "25"); 
    props.put("mail.debug", "true"); 
    props.put("mail.smtp.auth", "true"); 
    props.put("mail.smtp.starttls.enable","true"); 
    props.put("mail.smtp.EnableSSL.enable","true");
    
    props.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");   
    props.setProperty("mail.smtp.socketFactory.fallback", "false");   
    props.setProperty("mail.smtp.port", "465");   
    props.setProperty("mail.smtp.socketFactory.port", "465"); 
    

提交回复
热议问题