亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用帶 Java 的 SendGrid 發送電子郵件

使用帶 Java 的 SendGrid 發送電子郵件

江戶川亂折騰 2021-08-25 15:08:38
我是軟件開發的新手,一直在嘗試用 Java 開發一個應用程序,以使用 SendGrid 發送多內容電子郵件(純文本和 html 文件),但我只獲取 HTML 文件。請幫我解決這個問題。這是我的代碼。Email from = new Email("[email protected]");String subject = "Sending with SendGrid is Fun";Content content = new Content();content.setType("text/plain");content.setValue("This is a simple text");content.setType("text/html");content.setValue("This is an HTML text");Personalization personalization = new Personalization();Email to = new Email();to.setEmail("[email protected]");personalization.addTo(to);Email to2 = new Email();to2.setEmail("[email protected]");personalization.addTo(to2);Email Cc = new Email();Cc.setEmail("[email protected]");personalization.addCc(Cc);Mail mail = new Mail();mail.setFrom(from);mail.setSubject(subject);mail.addContent(content);mail.addPersonalization(personalization);endGrid sg = new SendGrid("SENDGRID API");Request request = new Request();try {    request.setMethod(Method.POST);    request.setEndpoint("mail/send");    request.setBody(mail.build());    Response response = sg.api(request);    System.out.println(response.getStatusCode());    System.out.println(response.getBody());    System.out.println(response.getHeaders());} catch (IOException ex) {    throw ex;}
查看完整描述

1 回答

?
嗶嗶one

TA貢獻1854條經驗 獲得超8個贊

您使用 HTML 覆蓋文本內容。

如果你想要兩者,你應該這樣寫:


Content plainContent = new Content("text/plain", "This is a simple text");

Content htmlContent = new Content("text/html", "This is an HTML text");

mail.addContent(plainContent);

mail.addContent(htmlContent);


查看完整回答
反對 回復 2021-08-25
  • 1 回答
  • 0 關注
  • 505 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號