【问题标题】:Sendgrid parse api in spring bootSpring Boot 中的 Sendgrid 解析 api
【发布时间】:2019-05-17 13:32:47
【问题描述】:

如何在 Spring boot 中实现 sendgrid 解析 API。

代码:

@RequestMapping(value = "/api/sendGridParse",method = RequestMethod.POST)
    public ResponseEntity<APIResponseDTO> sendGridParseDoamin(@ModelAttribute EmailParseDTO emailParseDTO )     
    {       
        APIResponseDTO _response = new APIResponseDTO();

        System.out.println("emailParseDTO:"+emailParseDTO.toString());
        try{            
            _response.setMessage("Success");
            _response.setStatus(100);
        }catch (Exception e) {
            e.printStackTrace();
            _response.setMessage("Failed");
            _response.setStatus(101);

        }
        return new ResponseEntity<APIResponseDTO>(_response, HttpStatus.OK);
    }

EmailParseDTO:

public class EmailParseDTO {

    int attachments;
    String charsets; 
    String from; 
    String headers; 
    String html; 
    String subject; 
    String envelope; 
    String text; 
    String to; 
    String cc;
//setter and getter

但它不会将解析后的数据发送到上面的 url。

例如:https://d3a26271.ngrok.io/api/sendGridParse

【问题讨论】:

  • 您发布的问题与手头的问题不匹配。代码中没有提到给定的 url。请使用相关代码发布您尝试过的内容。
  • 感谢 Sangam 的回复。我需要代码 sn-p 用于在 Spring boot 中发送网格解析器 API。就像每当向特定域发送任何邮件时一样。 abc.com.
  • Sendgrid 没有将解析后的数据发送到上面的 API。这是我在发送网格中配置的 URl (d3a26271.ngrok.io/api/sendGridParse)。我的 API 代码有什么问题吗?
  • 您需要在您的 application.properties 中添加您的相关密钥和 sendgrid 提供的其他详细信息。然后它应该将请求发送到 sendGrid 服务器。发送请求时您会得到什么响应?

标签: java spring-boot sendgrid


【解决方案1】:

根据这篇文章:https://varunsastrydevulapalli.medium.com/the-sendgrid-inbound-webhook-with-spring-dc7b5bae4e0c, 我们可以使用这个 spring 控制器接收入站消息:

@Controller
@RequestMapping(value = "/messaging")
public class InboundMessageController {
@Bean(name = "multipartResolver")
 public CommonsMultipartResolver commonsMultipartResolver() {
 CommonsMultipartResolver commonsMultipartResolver = new CommonsMultipartResolver();
 commonsMultipartResolver.setDefaultEncoding("UTF-8");
 commonsMultipartResolver.setMaxUploadSize(5000);
 return commonsMultipartResolver;
 }
 
 @RequestMapping(value = "/inbound", method = {RequestMethod.POST, RequestMethod.HEAD}, consumes = MediaType.MULTIPART_FORM_DATA)
 public @ResponseBody
 void processInboundSendGridEmails(HttpServletRequest request,
 HttpServletResponse response,
 @RequestParam(required = false) MultipartFile file,
 SendGridInbound sendGridInbound) {
  System.out.println(sendGridInbound);
 }
}

public class SendGridInbound {
    String headers;
    String dkim;
    String to;
    String html;
    String from;
    String text;
    String sender_ip;
    String spam_report;
    String envelope;
    String attachments;
    String subject;
    String spam_score;
    String attchmentInfo;
    String charsets;
    String spf;

    //getter setters toString
}

希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-29
    • 2021-05-13
    • 1970-01-01
    • 1970-01-01
    • 2019-08-14
    • 2018-12-18
    • 2021-05-28
    相关资源
    最近更新 更多