をだが、彼らのAPIドキュメントによると、エンドポイントは、実際に自分のJavaでさらに視線を取ると、送信者
ためのオプション「名前」属性をサポートしています
import com.sendgrid.*;
import java.io.IOException;
public class Example {
public static void main(String[] args) throws IOException {
Email from = new Email("[email protected]");
String subject = "Sending with SendGrid is Fun";
Email to = new Email("[email protected]");
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"));
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;
}
}
}
ソースコードを使用して、あなたはhere は、このに再加工することでし見られるように、電子メールのコンストラクタに「名前」を供給することができます:APIのソースコードは、それがこれですたとえば、次のようになります。
import com.sendgrid.*;
import java.io.IOException;
public class Example {
public static void main(String[] args) throws IOException {
Email from = new Email("[email protected]", "John Doe");
String subject = "Sending with SendGrid is Fun";
Email to = new Email("[email protected]", "Jane Smith");
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"));
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時間後に賞金を払うことができますが、それはあなたのものになるでしょう。 – coderodde
私はお手伝いできることを嬉しく思います。 – zack6849