使用Java SendGrid V3 API遇请求未找到问题?4.9.3版本Request类归属疑问
SendGrid Java 4.9.3版本适配问题解答
你使用的SendGrid Java 4.9.3版本确实不存在com.sendgrid.Request类——这个类是后续大版本(如v7及以上)才引入的API结构,官方文档的示例大概率是针对新版库编写的,因此和你当前的4.9.3版本不兼容,这也是你遇到“请求未找到”问题的根本原因。
适配4.9.3版本的正确代码
// using SendGrid's Java Library v4.9.3 import com.sendgrid.*; import java.io.IOException; public class Example { public static void main(String[] args) throws IOException { Email from = new Email("test@example.com"); String subject = "Sending with SendGrid is Fun"; Email to = new Email("test@example.com"); Content content = new Content("text/plain", "and easy to do anywhere, even with Java"); Mail mail = new Mail(from, subject, to, content); SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY")); // 4.9.3版本直接调用send方法发送Mail对象 Response response = sg.send(mail); System.out.println(response.getStatusCode()); System.out.println(response.getBody()); System.out.println(response.getHeaders()); } }
补充说明
- 在4.9.3版本中,发送邮件的核心逻辑是通过
SendGrid.send(Mail)方法完成的,无需手动构建Request对象。 - 若想使用文档中的
Request/Response模式,需要将库升级到v7及以上版本(该版本仍支持Java 8),但升级后可能需要调整部分API的调用方式。
内容的提问来源于stack exchange,提问作者Räyhä
相关产品推荐
相关产品推荐

