2012-12-10 12 views
8

Sto inviando email di massa utilizzando Amazon ses. Il mio codice è il seguenteInvio di e-mail HTML attraverso amazon ses

public void sendMail(String sender, LinkedList<String> recipients, String subject, String body) { 
    Destination destination = new Destination(recipients); 
    try { 
     ACCESS_KEY = EmailSender.prop.getProperty("accessKey"); 
     SECRET_KEY = EmailSender.prop.getProperty("secretKey"); 

     Content subjectContent = new Content(subject); 
     Content bodyContent = new Content(body); 
     Body msgBody = new Body(bodyContent); 
     Message msg = new Message(subjectContent, msgBody); 

     SendEmailRequest request = new SendEmailRequest(sender, destination, msg); 

     AWSCredentials credentials = new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY); 
     AmazonSimpleEmailServiceClient sesClient = new AmazonSimpleEmailServiceClient(credentials); 
     SendEmailResult result = sesClient.sendEmail(request); 

     System.out.println(result + "Email sent"); 
    }catch(Exception e) { 
     System.out.println("Exception from EmailSender.java. Email not send"); 
    } 

Qui mi hanno dato i miei contenuti html come stringa alla variabile "corpo".

La posta inviata correttamente. Ma ho ricevuto il contenuto html come email. Come inviare il contenuto HTML nella posta. Quali cambiamenti nel codice risolveranno questo problema?

+0

Ciò che l'e-mail ricevuta assomigliare? Cosa intendi con "Ho ricevuto il contenuto html come email"? In quale client email stai visualizzando la posta? – bdares

+0

Ho ricevuto la mail come ..... Intendo il codice html originale pieno di tag – Neeraj

+0

Che client di posta elettronica stai usando? – bdares

risposta

26

Dal Amazon SES developerGuide:

si dovrebbe utilizzare il metodo WithHtml:

Content subjContent = new Content().withData("Test of Amazon SES"); 
Message msg = new Message().withSubject(subjContent); 

// Include a body in both text and HTML formats 
Content textContent = new Content().withData("Hello - I hope you're having a good day."); 
Content htmlContent = new Content().withData("<h1>Hello - I hope you're having a good day.</h1>"); 
Body body = new Body().withHtml(htmlContent).withText(textContent); 
msg.setBody(body);