必须首先发出STARTTLS命令。使用Java和Google Apps发送电子邮件 [英] Must issue a STARTTLS command first. Sending email with Java and Google Apps

查看:739
本文介绍了必须首先发出STARTTLS命令。使用Java和Google Apps发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用用Lizard的代码来发送使用Google Apps的电子邮件。我收到这个错误:

I am trying to use Bill the Lizard's code to send an email using Google Apps. I am getting this error:

Exception in thread "main" javax.mail.SendFailedException: Sending failed;
  nested exception is: 
    javax.mail.MessagingException: 530 5.7.0 Must issue a STARTTLS command first. f3sm9277120nfh.74

    at javax.mail.Transport.send0(Transport.java:219)
    at javax.mail.Transport.send(Transport.java:81)
    at SendMailUsingAuthentication.postMail(SendMailUsingAuthentication.java:81)
    at SendMailUsingAuthentication.main(SendMailUsingAuthentication.java:44)

Bill的代码包含下一行,这似乎与错误有关:

Bill's code contains the next line, which seems related to the error:

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

然而,这没有帮助。

这些是我的import语句:

These are my import statements:

import java.util.Properties; 
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

有没有人知道这个错误?

Does anyone know about this error?

推荐答案

我发现问题。以前我正在使用j2ee.jar来导入javax.mail。

I found the problem. Previously i was using j2ee.jar to import javax.mail.

我从类路径中删除了j2ee.jar,并下载了 JavaMail 1.4.1并放入我的classpath两个jar,smtp.jar和mailapi.jar。我现在使用 smtps 代替 smtp

I removed j2ee.jar from the classpath and downloaded JavaMail 1.4.1 and put into my classpath two jars, smtp.jar and mailapi.jar. I use now smtps instead smtp

Transport transport = session.getTransport("smtps");            

现在,比尔蜥蜴的代码可以工作。

Now Bill the Lizard's code works.

这篇关于必须首先发出STARTTLS命令。使用Java和Google Apps发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆