Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在Springboot应用程序中使用Godaddy webmail发送电子邮件_Java_Spring - Fatal编程技术网

Java 如何在Springboot应用程序中使用Godaddy webmail发送电子邮件

Java 如何在Springboot应用程序中使用Godaddy webmail发送电子邮件,java,spring,Java,Spring,当我可以使用Gmail成功发送电子邮件,但当我使用Godaddy webmail时,我得到以下信息: Failed message 1: javax.mail.MessagingException: Could not connect to SMTP host: smtpout.asia.secureserver.net, port: 465, response: -1] with root cause javax.mail.MessagingException: Could not con

当我可以使用Gmail成功发送电子邮件,但当我使用Godaddy webmail时,我得到以下信息:

Failed message 1: javax.mail.MessagingException: Could not connect to SMTP 
host: smtpout.asia.secureserver.net, port: 465, response: -1] with root 
cause
javax.mail.MessagingException: Could not connect to SMTP host: 
smtpout.asia.secureserver.net, port: 465, response: -1
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2106) ~
[javax.mail-1.5.6.jar:1.5.6]
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:712) ~
[javax.mail-1.5.6.jar:1.5.6]
at javax.mail.Service.connect(Service.java:366) ~[javax.mail-
1.5.6.jar:1.5.6]
spring.mail.properties.mail.smtp.ssl.enable=true
spring.mail.properties.mail.smtp.ssl.trust=*
这是我的属性文件

spring.mail.host =  smtpout.asia.secureserver.net
spring.mail.username=  xyz@domian.com
spring.mail.password= ******

spring.mail.properties.mail.transport.protocol=smtp

spring.mail.properties.mail.smtp.port=465
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.timeout=60000
spring.mail.properties.mail.imap.ssl.enable=true
spring.mail.properties.mail.imap.ssl.trust=*
这是我的密码

//SendMail using java Mail API
@Autowired
JavaMailSender mailSender;

public String send(String to, String Subject, String Password) throws 
MessagingException{

    MimeMessage message = mailSender.createMimeMessage();
    MimeMessageHelper helper;

    helper = new MimeMessageHelper(message, true);

    helper.setSubject(Subject);
    helper.setTo(to);
    helper.setText("Your password is:"+Password);
    mailSender.send(message);
    return "false";
}

此问题与JAVA代码无关,它似乎与SMTP协议的服务器设置有关

然而,我怀疑您在JAVA中的SMTP配置中可能遗漏了一些东西,我建议您在下面给出一些相关的提示

  • 将本地SMTP服务器配置为本地服务器上的中继,以便
    检查你是否在正确的轨道上
  • 您甚至可以配置虚拟服务器来跟踪电子邮件请求
  • 同时检查防火墙设置,可能会受到限制 对于其他SMTP服务器

    • 当我在Stackoverflow中找到一个可行的解决方案时,我也遇到了同样的问题,并且快要发疯了,尽管我丢失了链接,我很抱歉

      在这个遗留项目中,我使用的是Spring3.x。邮件是使用org.springframework.Mail.javamail.JavaMailSenderImpl发送的,配置如下:

      <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
          <property name="host" value="${mail.server.host}" />
          <property name="port" value="${mail.server.port}" />
          <property name="protocol" value="${mail.server.protocol}" />
          <property name="username" value="${mail.server.username}" />
          <property name="password" value="${mail.server.password}" />
          <property name="javaMailProperties">
              <util:properties location="classpath:javamail.properties" />
          </property>
      </bean>
      
      这很有效

      请注意,某些属性中的协议是smtps,而其他属性中的协议是smtp。

      Thakur

      我得到了与您完全相同的错误,但现在我得到了基于您的代码的解决方案

      尝试将以下内容添加到属性中:

      Failed message 1: javax.mail.MessagingException: Could not connect to SMTP 
      host: smtpout.asia.secureserver.net, port: 465, response: -1] with root 
      cause
      javax.mail.MessagingException: Could not connect to SMTP host: 
      smtpout.asia.secureserver.net, port: 465, response: -1
      at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2106) ~
      [javax.mail-1.5.6.jar:1.5.6]
      at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:712) ~
      [javax.mail-1.5.6.jar:1.5.6]
      at javax.mail.Service.connect(Service.java:366) ~[javax.mail-
      1.5.6.jar:1.5.6]
      
      spring.mail.properties.mail.smtp.ssl.enable=true
      spring.mail.properties.mail.smtp.ssl.trust=*
      

      你的问题发生了,因为GoDaddy在他们的连接请求中需要SSL,否则他们不会响应你的请求!另外,我曾经测试我的smtp连接,看看它是否工作。您可以使用它来检查您的问题是否也是缺少SSL。

      我使用的是Spring Boot 2.2 an,可用于此配置:

      mail.server.protocol=smtps
      mail.smtps.quitwait=false
      mail.smtp.auth=true
      mail.smtp.starttls.enable=true
      
      spring.mail.host=smtpout.secureserver.net
      spring.mail.port=465
      spring.mail.username=your_email@example.com
      spring.mail.password=your_password
      # Other properties
      spring.mail.properties.mail.smtp.auth=true
      # TLS, port 587
      #spring.mail.properties.mail.smtp.starttls.enable=true
      # SSL, port 465
      spring.mail.properties.mail.smtp.socketFactory.port=465
      spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
      
      当您使用gmail时,协议通常是TLS,但是GoDaddy看起来像只使用SSL,所以我对TLS配置进行注释并启用SSL配置

      当您发送电子邮件(与spring.mail.username中的相同)或收到错误时,必须从中设置de field

      SimpleMailMessage message = new SimpleMailMessage();
      message.setFrom("your_email@example.com");
      ...
      
      希望能帮助你


      PD:在谷歌搜索了很多次后,我在中找到了解决方案:

      这与代码无关,错误消息说它无法连接到给定端口上的给定服务器。您确定连接正常吗?您是否可以从主机访问该端口上的服务器?您可以使用nmap或任何其他工具来查找。是的,我使用的是相同的smtp服务器和相同的服务器,但serverport在outlook中是SSL(安全套接字层),然后工作,但在此代码中不工作。OK,但您是说在imap上启用了SSL,而不是smtp,但这就是问题所在?spring.mail.properties.mail.smtp.ssl=true?我不使用spring.mail.properties.mail.imap.ssl=truespring.mail.properties.mail.imap.ssl=true,而是使用它,但收到错误消息“message”:“邮件服务器连接失败;嵌套异常为javax.mail.MessaginException:无法连接到SMTP主机:smtpout.asia.secureserver.net,端口:465,响应:-1。失败邮件:javax.mail.MessagineException:无法连接到SMTP主机:smtpout.asia.secureserver.net,端口:465,响应:-1“,感谢您的感谢,如果此答案对您有帮助,则您可以提供您的接受:)。