2017-12-04 6 views
0

私はSendGrid API v3 for Javaを使用しています。それは働き、仕事をします。しかしながら、センダが、例えば、[email protected]である場合、受信者はそれだけを見ると、[email protected]となる。SendGrid:送信者の単純な電子メールアドレス以外の名前を追加する方法

Example sender address and name

(上、実際のアドレスは[email protected]で、まだそれはKela Fpaで先行していることに注意してください:私は何を達成しようとすると、受信者はまた、このような(例えば、Hello World <[email protected]>)単純な名前を見ているということです。 )

これをプログラムで行うにはどうすればよいですか?あなたのコードがなければ、それはやって正確に何を示唆するのは難しい

答えて

2

をだが、彼らの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; 
    } 
    } 
} 

メールコンストラクタは変更されています。

何らかの理由でメールヘルパークラスを使用していない場合は、教えてください。

+0

それは仕事です、ありがとう!それで私は1時間後に賞金を払うことができますが、それはあなたのものになるでしょう。 – coderodde

+1

私はお手伝いできることを嬉しく思います。 – zack6849

関連する問題