我知道這個問題已經被問過,但我嘗試了幾個解決方案,問題仍然存在,所以和幫助將不勝感激。發送電子郵件與駱駝Java。 ISSUE STARTTLS錯誤
我想配置發送電子郵件throu gmail和smtp。下面是我們的駱駝配置:
<camel:camelContext xmlns="http://camel.apache.org/schema/spring">
<camel:route id="gmailRoute">
<camel:from uri="direct://gmail" />
<camel:to
uri="smtp://p****[email protected]?host=smtp.gmail.com&port=587&from=p****[email protected]&password=gl******" />
</camel:route>
對我們的服務實現的init方法,我們有以下幾點:
log.info("Initializing Email Service");
Properties props = new Properties();
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.googlemail.com");
props.put("mail.smtp.port", "587");
Authenticator auth = null;
props.put("mail.smtp.auth", "true");
auth = new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("******[email protected]", "gl*****s");
}
};
Session t = Session.getInstance(props, auth);
template = camelContext.createProducerTemplate();
和sendmail的方法有:
@Override
public void sendEmail(String from, String[] to, String[] cc, String[] bcc, String subject, String body)
{
String endpoint = "direct://gmail";
String toString = null;
String ccString = null;
String bccString = null;
Map<String, Object> headers = null;
toString = convertStringArrayToCSV(to);
ccString = convertStringArrayToCSV(cc);
bccString = convertStringArrayToCSV(bcc);
headers = new HashMap<String, Object>();
headers.put("Subject", subject);
if (toString != null)
{
headers.put("To", toString);
}
if (ccString != null)
{
headers.put("CC", ccString);
}
if (bccString != null)
{
headers.put("BCC", bccString);
}
template.sendBodyAndHeaders(endpoint, body, headers);
}
問題當我們嘗試使用sendmail方法發送電子郵件時,我們得到以下錯誤:
caught: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first.
任何想法將不勝感激。
在這種情況下,我只是得到javax.net.ssl.SSLException:無法識別的SSL消息,純文本連接? – kaqqao