简体   繁体   中英

Sending HTML email but delivered as plain text, why?

I am using sendgrid, and this is my java code:

public void sendEmail(String templateID){

    SendGrid sendgrid = new SendGrid("username", "password");

    Email email = new Email();

    email.addTo("...");
    email.addToName("...");
    email.setFrom("...");
    email.setSubject("...");
    email.setText("...");
    email.setTemplateId(templateID);

    try {
        sendgrid.send(email);
    } catch (SendGridException ex) {
        Logger.getLogger(FXMLEditNewsLetterController.class.getName()).log(Level.SEVERE, null, ex);
    }

}

The mails are being sent(I don't know why they are received as junk!!) but they are being delivered as plain text. Can someone help me, and if you need any additional information, please let me know.

The emails are being sent as plain text because you are using email.setText(). Try using email.setHtml() instead if the content of the message is HTML.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM