How to set From as a name in SparkPost email - java

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

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
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.

Related

Get TextBody for an email through the ews-java-api

It seems not to be possible to get email body as plain text if there is some in mime encoded mail. How to work around it?
I solved the problem. When you get the item
ExchangeService.bindToItem(EmailMessage.class, itemId, PROPERTY_SET_TEXT_BODY).getBody() use need use following property set and then set request body type to BodyType.Text
PropertySet PROPERTY_SET_TEXT_BODY = new PropertySet(ItemSchema.Body);
PROPERTY_SET_TEXT_BODY.setRequestedBodyType(BodyType.Text);

Receive Email address instead of Name with POI from *.msg-File [Java]

i wrote a small java programm which extract the names,email address, subject, bodytext from a *.msg by using POI 3.15 and writes it to an excel sheet.
By reading the MAPIMessage API Documentation i saw:
getDisplayFrom() --> Gets the display value of the "FROM" line of the outlook message This is not the actual address that was sent from but the formated display of the user name.
Now i would like to get the email address from sender instead of his stored nickname.
Just btw - for receiving the Emailaddress of all "to"-persons you can use getRecipientEmailAddress().
Any suggestions how to deal with it?
thanks in advance
Edit:
I just noticed you can use the first element of getHeaders() to get the Return-Path - which is the emailaddress of "from". kinda dirty way ... so my question is still up to be answered ;)
I don't know in previous versions, but in 3.17 you can get it from main chunks.
MAPIMessage msg = new MAPIMessage("email.msg");
Chunks mainChunks = msg.getMainChunks();
StringChunk emailFromChunk = mainChunks.getEmailFromChunk();
String emailFrom = emailFromChunk.getValue();

How do i send HTML email containing dynamic link via JAVA

I am trying to send a dynamic link via email with the following code.
Message messageSSL = new MimeMessage(session);
int hash=1000;
String content="click here";
messageSSL.setContent(content, "text/html");
However, i have failed to generate a dynamic link.The output in the mail is in the plain text format.
Output (In the mail):
click here
Even though, the following code works and generates a link called "click here".
String content="click here";
Thanks!!
I think the problem is with backward slash. We should be using forward slash in urls. Please change and try it.
The Apache Commons Email library has some useful classes that take care of the low-level details for stuff like making HTML email work properly. Check it out:
http://commons.apache.org/proper/commons-email/
can you please enclose the link by html tag and try once.
String content="<html><body>click here </body></html>";
i am using same library and working fine for me.
please check below thread
How Can I put a HTML link Inside an email body?

sending String using servlet while dowloading in GWT

i am using GWT
I trying to dowload a file using Servlet.
I have fileId on the client side.
i have my servlet ready to look for the file using fileId and send back to client.
But on the Client side.
I dont understand how to send this id and retrieve this on server side to use it.
String fileId = "aValidId"
Window.open(GWT.getHostPageBaseURL() + "DownloadFileServlet", "", "");
Can any one help me to do this.
If this question is repeated , please send me a link (i could not find it )
Thanks in advance
You can simply append the parameter to the servlet path like below
String fileId = "aValidId"
Window.open(GWT.getHostPageBaseURL() +
"DownloadFileServlet?fileId ="+fileId , "", "");
And in servlet get the parameter like below:
String myParam = req.getParameter("myparam");
And please go through the below link for encoding and for other techniques..
http://perishablepress.com/how-to-write-valid-url-query-string-parameters/

org.apache.commons.mail attachment file name encoding

I'm using apache commons mail for sending e-mails with attachments.
My attachment file content is in hebrew and I can see it when I open the file , my problem is when the attachment file name is in hebrew I can't see the name I see ??? instead. (the content I still see o.k).
this is my code:
String attachment_file_name = "קובץ מס 1";
HtmlEmail email = new HtmlEmail();
email.setHostName(smtp_server);
email.addTo(to_email;
email.setFrom(from_email , "XXXXXXX");
email.setSubject(subject);
email.setCharset("UTF-8");
email.setHtmlMsg(body);
email.attach(new ByteArrayDataSource(attachment_file_.toByteArray(), "application/pdf"),
attachment_file_name ,
"attachment pdf",
EmailAttachment.ATTACHMENT);
email.send();
what do I need to do inorder to see the file name in hebrew (in the correct encoding) ?
Thank's In Advance.
I believe you have to encode it.
Javamail, the core library requires this
Set the System property "mail.mime.encodeparameters" to "true".

Categories