Javax-中继访问被拒绝

时间:2018-11-13 16:35:39

标签: java spring

我正在使用spring通过简单的控制器发送电子邮件。到目前为止,这是我的代码。

@Controller
@RequestMapping("/send")
public class EmailSenderController {

    @RequestMapping(method = RequestMethod.GET, value = "/email")
    public void send(){
        String[] to = {"firstmail@gmail.com", "secondmail@hotmail.com"};
        try {
            EmailSender.sendMessage(to, "My subject", "My body");
            System.out.println("OK");
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("Error");
        }
    }
}

@Service
public final class EmailSender {

    /* SMTP SERVER */
    private static String SMTP_HOST = "";
    private static int SMTP_PORT = 587;
    private static boolean SMTP_SSL_ENABLE = false;
    private static String SMTP_FROM = "my@email.com";
    private static boolean SMTP_AUTH = true;
    private static String SMTP_USER = "";
    private static String SMTP_PASSWORD = "";
    private static String SMTP_EMAIL_DEFAULT_TEMPLATE = "/my_template.html";

    /* getters and setters */
}

我收到以下错误:

Caused by: javax.mail.SendFailedException: Invalid Addresses;
  nested exception is:
    com.sun.mail.smtp.SMTPAddressFailedException: 454 4.7.1 <firstmail@gmail.com>: Relay access denied;
  nested exception is:
    com.sun.mail.smtp.SMTPAddressFailedException: 454 4.7.1 <secondmail@hotmail.com>: Relay access denied

奇怪的是我的同事在他的笔记本电脑上执行了相同的代码,并且可以正常工作。我的意思是这个确切的代码,切换到我正在处理的分支。那么这可能是我的笔记本电脑上缺少的配置吗?谢谢。

0 个答案:

没有答案