使用godaddy从spring app发送电子邮件

时间:2016-03-27 18:22:17

标签: spring email

您好我正试图使用​​godaddy电子邮件从我的春季启动应用程序发送邮件。 我已经购买了域名和电子邮件ID。现在我想从该域发送邮件,但它显示出一些错误。

public boolean sendMail(String to, String subject, String content) {
        String from = "info@mydomain.com";
        String password ="***********";
        try {
              Properties props = System.getProperties();
              props.setProperty("mail.transport.protocol", "smtp");
              props.setProperty("mail.host", "smtpout.mydomain.com");

             props.put("mail.smtp.starttls.enable","true" );
             props.put("mail.smtp.auth", "true");
             props.setProperty("mail.user", from);
             props.setProperty("mail.password", password);

            Session mailSession = Session.getDefaultInstance(props);
            // mailSession.setDebug(true);
            Transport transport = mailSession.getTransport("smtp");
            MimeMessage message = new MimeMessage(mailSession);
            message.setSentDate(new java.util.Date());
            message.setSubject(subject);
            message.setFrom(new InternetAddress(from));
            message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
            message.setContent(content, "text/html");
            transport.connect("smtpout.mydomain.com",from,password);
            transport.sendMessage(message,
             message.getRecipients(Message.RecipientType.TO));
            transport.close();

            } catch (Exception e) {
                e.printStackTrace();
            }
        return false;
    }

错误:

com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtpout.mydomain.com, 25; timeout -1;
  nested exception is:
    java.net.ConnectException: Connection refused: connect

0 个答案:

没有答案