JavaMail Issue : Can't send command to SMTP host

前端 未结 5 1172
南方客
南方客 2021-01-12 16:15

I\'m trying to do java mail and im getting an error \"Cant send command to SMTP host\". Any help would be appreciated. And any future problems\' solutions if possible. The e

相关标签:
5条回答
  • 2021-01-12 16:44

    The server requires STARTTLS. Here's what I get if I do a manual SMTP session with telnet:

    220 BLU0-SMTP122.phx.gbl Microsoft ESMTP MAIL Service, Version: 6.0.3790.4675 ready at  Mon, 18 Jul 2011 17:08:14 -0700
    HELO jhmg.net
    250 BLU0-SMTP122.phx.gbl Hello [70.123.155.64]
    MAIL FROM:<zzz@zzz.com>
    530 5.7.0 Must issue a STARTTLS command first
    

    This server does not accept unencrypted connections

    0 讨论(0)
  • 2021-01-12 16:45

    Today I gone through this same issue. But for me the issue is, in smtp server TLS was not enabled. So I have changed the mail properties like this.
    mail.smtp.starttls.enable=false

    Now every thing is working good for me.

    0 讨论(0)
  • 2021-01-12 16:51

    Try adding from address

    mail.setFromAddress("Name ");

    0 讨论(0)
  • 2021-01-12 16:53

    In my case, I was able to find the root problem after I enabled mailer debugging.

    Different ways to enable mailer debugging:

    java -Dmail.debug=true ...

    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.debug", "true");
    

    Jenkins config (/etc/default/jenkins):

    JAVA_ARGS="-Dmail.smtp.starttls.enable=true -Dmail.debug=true"

    More info: http://www.oracle.com/technetwork/java/faq-135477.html

    My particular error was that I had an incorrect address in the "from:" line when the email was created. Google "G Suite" (google apps for business) requires the from-address to be in the same domain as the account owner. Eg. mycompanyname.com

    The mailer debug revealed:

    MAIL FROM:<jenkins-pipeline@bogusdomain.com> 550-5.7.1 Invalid credentials for relay [192.168.42.42]. The IP address you've 550-5.7.1 registered in your G Suite SMTP Relay service doesn't match domain of 550-5.7.1 the account this email is being sent from. If you are trying to relay 550-5.7.1 mail from a domain that isn't registered under your G Suite account

    0 讨论(0)
  • 2021-01-12 17:04

    You need to set ssl trust to smtp.gmail.com

    properties.put("mail.smtp.ssl.trust", "smtp.gmail.com");
    

    and Authenticator as a parameter for session

    
            Session session = Session.getDefaultInstance(properties,new javax.mail.Authenticator(){
                protected PasswordAuthentication getPasswordAuthentication() {
    
                    return new PasswordAuthentication(
                            sender, senderPassword);// Specify the Username and the PassWord
                }
            });
    
    0 讨论(0)
提交回复
热议问题