AsyncEmailServiceImpl.java 文件源码

java
阅读 26 收藏 0 点赞 0 评论 0

项目:c4sg-services 作者:
/**
 * Sends an email message asynchronously through SendGrid.
 * Status Code: 202 - ACCEPTED: Your message is both valid, and queued to be delivered.
 *
 * @param from      email address from which the message will be sent.
 * @param recipient array of strings containing the recipients of the message.
 * @param subject   subject header field.
 * @param text      content of the message.
 */
@Async
public void send(String from, String recipient, String replyTo, String subject, String text) throws IOException {

    Email emailFrom = new Email(from);
    String emailSubject = subject;
    Email emailTo = new Email(recipient);

    Content emailContent = new Content("text/html", text);
    Mail mail = new Mail(emailFrom, emailSubject, emailTo, emailContent);
    if (!replyTo.isEmpty()) {
        Email emailReplyTo = new Email(replyTo);
        mail.setReplyTo(emailReplyTo);
    }

    SendGrid sg = new SendGrid(sendgridApiKey);
    Request request = new Request();
    request.setMethod(Method.POST);
    request.setEndpoint("mail/send");
    request.setBody(mail.build());

    sg.api(request);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号