0

I'm using Sparkpost client library for java.

When I set a fromEmailand username to contentAttributes I expect to see Name Name instead of name@mydomain.com in email I have got. But it doesn't work. Is there any way to show Name instead of Email in message?

place where I need my name instead of email address

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 Answers1

1

maintainer of the Java SparkPost library here. I just modified this sample.

I changed it to this:

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

And this is the result enter image description here

Is it possible "username" is an empty string. If you look at the source in your email client do you see the friendly name?

If you are still having problem please share the JSON that is sent to the server.

Yepher
  • 1,465
  • 12
  • 25
  • It works when I set name and email directly there but don't if I send those from another method. Have no idea why it works this way. Thank You! – Andrei Golimbievsky May 08 '17 at 22:49
  • I am not sure what exactly you mean. But if you think it is a bug it would be great if you could create an issue in GitHub for it. You can create the issue here https://github.com/SparkPost/java-sparkpost/issues – Yepher May 09 '17 at 11:23