javax.mail.MessagingException: 500 Error: bad syntax问题

原创
2018/01/16 19:58
阅读数 980

在eclipse下执行下面这个发送邮件的方法报错:

public static void sendSimpleMail() throws GeneralSecurityException {
		JavaMailSenderImpl senderImpl = new JavaMailSenderImpl();
		senderImpl.setHost("xxx");
		senderImpl.setUsername("xxx");
		senderImpl.setPassword("xxx");
		
		Properties prop = new Properties();
		MailSSLSocketFactory sf = new MailSSLSocketFactory();
		sf.setTrustAllHosts(true);
		prop.put("mail.smtp.ssl.enable", "true");
		prop.put("mail.smtp.ssl.socketFactory", sf);
		prop.put("mail.smtp.auth", "true");
		prop.put("mail.smtp.timeout", "20000");
		senderImpl.setJavaMailProperties(prop);
		
		SimpleMailMessage mail = new SimpleMailMessage();
		mail.setFrom("xxx");
		mail.setTo("xxx");
		mail.setSubject("激活通知");
		mail.setText("我在学生时代最喜欢哪个电影明星或角色?");
		senderImpl.send(mail);
		System.out.println("SIMPLEMAIL SENDED");
	}

错误如下:

javax.mail.MessagingException: 500 Error: bad syntax
at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1363)
at com.sun.mail.smtp.SMTPTransport.helo(SMTPTransport.java:838)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:375)
at javax.mail.Service.connect(Service.java:297)
at javax.mail.Service.connect(Service.java:156)
at javax.mail.Service.connect(Service.java:105)
at javax.mail.Transport.send0(Transport.java:168)
at javax.mail.Transport.send(Transport.java:98)

在网上找了半天也没解决问题,这里有一篇,很像我的异常,但按照方法一样解决不了问题,后来突然想着是不是文件编码问题,果然,用notepad打卡那个java文件发现右下角:

这里并是 Unix而是Windows,我改为 Unix之后再运行,邮件发送成功!

展开阅读全文
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部