gpt4 book ai didi

java - 发送电子邮件的问题 sendgrid

转载 作者:行者123 更新时间:2023-12-02 10:49:04 25 4
gpt4 key购买 nike

我使用 sendgrid 发送电子邮件,但出现以下错误。我的代码位于错误下方。

Error:  Caused by: java.lang.NoSuchFieldError: No static field INSTANCE of type Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier; in class Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier; or its superclasses (declaration of 'org.apache.http.conn.ssl.AllowAllHostnameVerifier' appears in /system/framework/framework.jar:classes3.dex)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:144)
at

电子邮件消息代码:

Email from = new Email("zihronProjectManagementApp@gmail.com");

String subject = "Sending with SendGrid is Fun";

Email to = new Email("ayobami.o.idowu@gmail.com");

Content content = new Content("text/plain", "and easy to do anywhere, even with Java");

Mail mail = new Mail(from, subject, to, content);

//Toast.makeText(getApplicationContext(),System.getenv('"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"),Toast.LENGTH_LONG).show();

SendGrid sg = new SendGrid(System.getenv("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"));

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) {


}

我已经尝试了 Stack Overflow 上所有可能的帖子。请帮助我我做错了什么?

最佳答案

org.apache.http.conn.ssl.AllowAllHostnameVerifier

以上类已被删除 API 级别 22

您应该使用HttpURLConnection类代替。

关于java - 发送电子邮件的问题 sendgrid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52319046/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com