2017-05-08 111 views
0

我正在使用Sparkpost客戶端庫for java。如何設置從作爲SparkPost郵件中的名稱

當我將fromEmailusername設置爲contentAttributes時,我希望在電子郵件中看到Name Name而不是[email protected]。但它不起作用。有沒有什麼方法可以在郵件中顯示名稱而不是電子郵件?

place where I need my name instead of email address

了Java SparkPost庫這裏的
TemplateContentAttributes contentAttributes = new TemplateContentAttributes(); 

    AddressAttributes addressAttributes = new AddressAttributes(); 
    addressAttributes.setName(username); 
    addressAttributes.setEmail(fromEmail); 

    contentAttributes.setFrom(addressAttributes); 
    contentAttributes.setSubject(subject); 
    contentAttributes.setHtml(html); 
    contentAttributes.setText(text); 

回答

1

維護者。我只是修改了這個sample

我改成了這樣:

TemplateContentAttributes contentAttributes = new TemplateContentAttributes(); 
AddressAttributes fromAddress = new AddressAttributes(from); 
fromAddress.setName("My Name"); 
contentAttributes.setFrom(fromAddress); 

這是結果 enter image description here

是否有可能 「用戶名」 是一個空字符串。如果你看看你的電子郵件客戶端的源代碼,你會看到友好的名字嗎?

如果您仍有問題,請分享發送到服務器的JSON。

+0

它直接在那裏設置名稱和電子郵件,但如果我從其他方法發送這些名稱和電子郵件,它的工作原理。不知道爲什麼它以這種方式工作。 謝謝! –

+0

我不確定你的意思。但是如果你認爲這是一個bug,如果你可以在GitHub中爲它創建一個問題,那將是非常好的。你可以在這裏創建問題https://github.com/SparkPost/java-sparkpost/issues – Yepher

相關問題