2014-01-30 52 views
1

在下面我試圖2個組合亞馬遜SES 535驗證憑證無效

  1. 用戶(參照附加圖像),密碼
  2. 訪問ID和訪問密鑰

代碼兩人都給出了同樣的錯誤。我在家庭網絡的eclipse環境中運行了這段代碼。

錯誤

Attempting to send an email through the Amazon SES SMTP interface... 
The email was not sent. 
Error message: 535 Authentication Credentials Invalid 

Amazon SES Users

代碼

public class amazon_ses_smtp_test { 

    static final String FROM = "[email protected]"; // This has been verified on the Amazon SES setup 
    static final String TO = "[email protected]"; // I have production access 

    static final String BODY = "This email was sent through the Amazon SES SMTP interface by using Java."; 
    static final String SUBJECT = "Amazon SES test (SMTP interface accessed using Java)"; 

    static final String SMTP_USERNAME = "tried username and tried accesskey here"; 
    static final String SMTP_PASSWORD = "tried the password and the access key"; 

    static final String HOST = "email-smtp.us-east-1.amazonaws.com";  

    static final int PORT = 25; 

    public static void main(String[] args) throws Exception { 

     Properties props = System.getProperties(); 
     props.put("mail.transport.protocol", "smtp"); 
     props.put("mail.smtp.port", PORT); 

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

     Session session = Session.getDefaultInstance(props); 

     MimeMessage msg = new MimeMessage(session); 
     msg.setFrom(new InternetAddress(FROM)); 
     msg.setRecipient(Message.RecipientType.TO, new InternetAddress(TO)); 
     msg.setSubject(SUBJECT); 
     msg.setContent(BODY,"text/plain"); 

     Transport transport = session.getTransport(); 

     try 
     { 
      System.out.println("Attempting to send an email through the Amazon SES SMTP interface..."); 

      transport.connect(HOST, SMTP_USERNAME, SMTP_PASSWORD); 
      transport.sendMessage(msg, msg.getAllRecipients()); 
      System.out.println("Email sent!"); 
     } 
     catch (Exception ex) { 
      System.out.println("The email was not sent."); 
      System.out.println("Error message: " + ex.getMessage()); 
     } 
     finally 
     { 
      transport.close();   
     } 
    } 
} 
+0

我不認爲你可以使用25端口 – Toolkit

回答

1

的問題是在我們與下面的情況:在AWS SMTP在其證書有特殊字符。憑證必須經過網址編碼,然後在配置中提供。