Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attachment Name does not show Norwegian Characters #19

Closed
PrinceVarshney opened this issue Mar 15, 2017 · 26 comments
Closed

Attachment Name does not show Norwegian Characters #19

PrinceVarshney opened this issue Mar 15, 2017 · 26 comments
Labels
difficulty: medium fix is medium in difficulty status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap type: twilio enhancement feature request on Twilio's roadmap

Comments

@PrinceVarshney
Copy link

Issue Summary

I am new to SendGrid, I wanted to send a mail with attachment having Norwegian characters in the name. Receiver is receiving the mail but the name contains Å instead of Ø. Saw the Client class , it contains the change for UTF characters

sendgrid-java v3.1.0 is being used. Not using the java-http-client. I visited few related issues but was not able to get which api version include this change. Its urgent for me as we are going in production in two weeks.

Please help!

@thinkingserious
Copy link
Contributor

Hello @PrinceVarshney,

I believe you are asking for us to update the dependency in sendgrid-java to support v4.1.0 of this library. Correct?

If so, here is the ticket for that: sendgrid/sendgrid-java#162 -- I will add your vote to that issue to grant it higher priority.

With Best Regards,

Elmer

@thinkingserious thinkingserious added status: help wanted requesting help from the community type: question question directed at the library labels Mar 15, 2017
@PrinceVarshney
Copy link
Author

PrinceVarshney commented Mar 15, 2017

Hei @thinkingserious
I am not able to get why its converting Ø -->Å , because the Client.java class has the UTF-8 support then why I am facing the issue.. ? Is this because of the dependency thats not included in sendgrid-java v3.1.0 ,I can externally include the dependency of httpClient if its required. But will it help. ? I need a urgent fix as we are moving in production in few days.

Please help!!

@thinkingserious
Copy link
Contributor

Hello @PrinceVarshney,

I'm not sure what is causing that issue, I am attempting to clarify with you.

Let me make sure my assumptions are correct:

  1. You are using the sendgrid-java SDK v3.1.0.
  2. I think that a similar issue was fixed with this PR: Fix charset: Use "UTF-8" charset instead of default "ISO-8859-1" #5

Also, can you please provide me with the sample file so that I can try to re-create the issue?

Thanks!

Elmer

@PrinceVarshney
Copy link
Author

@thinkingserious

Yeah I am using sendgrid-java SDK v3.1.0.

We are creating runtime content and the name of the pdf visible to the user is
Pris og oppgjørsvilkår.pdf

that should be
Pris og oppgjørsvilkår.pdf

This is where I am attaching the file

Attachments attachments=new Attachments();
Charset.forName("UTF-8").encode(attachmentName);
attachments.setFilename(attachmentName);
attachments.setType(type);
attachments.setDisposition("attachment");
attachments.setContent(Base64.encodeBase64String(attachment));
List attachList = new ArrayList();
attachList.add(attachments);
emailDTO.setAttachment(attachList);

While sending it through sendgrid :
Attached the file for the reference-
sampleFile.txt

@thinkingserious
Copy link
Contributor

Hello @PrinceVarshney,

I was unable to reproduce the error, here is the code I used:

import com.sendgrid.*;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class Example {

  public static Mail buildHelloEmail() throws IOException {
    Email from = new Email("[email protected]");
    String subject = "Hello World from the SendGrid Java Library";
    Email to = new Email("[email protected]");
    Content content = new Content("text/plain", "some text here");
    Mail mail = new Mail(from, subject, to, content);

    Attachments attachments = new Attachments();
    attachments.setContent("TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12");
    attachments.setType("application/pdf");
    attachments.setFilename("Pris og oppgjørsvilkår.pdf");
    attachments.setDisposition("attachment");
    attachments.setContentId("Balance Sheet");
    mail.addAttachments(attachments);

    return mail;
  }

  public static void baselineExample() throws IOException {
    SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
    Request request = new Request();
    Mail helloWorld = buildHelloEmail();
    try {
      request.method = Method.POST;
      request.endpoint = "mail/send";
      request.body = helloWorld.build();
      Response response = sg.api(request);
      System.out.println(response.statusCode);
    } catch (IOException ex) {
      throw ex;
    }
  }

  public static void main(String[] args) throws IOException {
    baselineExample();
  }
}

Perhaps the value in attachmentName is getting changed before you pass it into the setFilename function.

@PrinceVarshney
Copy link
Author

Hey @thinkingserious
I hardcoded the value in the attachment name, then also I was facing the same error. You are using the same version of sendgrid-java. ?

@thinkingserious
Copy link
Contributor

@PrinceVarshney,

Yes, I am using the latest version 3.1.0.

Can you check the encoding on your source code editor?

@PrinceVarshney
Copy link
Author

@thinkingserious

Will it matter. ? I think you are talking about eclipse. ?

Whats the use of below line ?

sg.addRequestHeader("X-Mock", "true");

@thinkingserious
Copy link
Contributor

That line can be ignored, it is for when we use our local testing server. I just tried without that line with the same result.

For Eclipse: http://stackoverflow.com/questions/9180981/how-to-support-utf-8-encoding-in-eclipse

@PrinceVarshney
Copy link
Author

My request in the logs is printed correctly :
"type":"application/pdf","filename":"Pris og oppgjørsvilkår.pdf","disposition":"attachment"}

so does the eclipse encoding will matter.. ?

@thinkingserious
Copy link
Contributor

I'm not sure.

Can you please try sending your test email to [email protected]?

@PrinceVarshney
Copy link
Author

@thinkingserious

I have sent one mail on this id. One thing I observed that the issue is with MicrosoftOutlook only, in gmail its fine.

@thinkingserious
Copy link
Contributor

Hello @PrinceVarshney,

I have received the email correctly in GMail. Since the filename is correct on your server and in GMail, it appears the issue is with Outlook and that it might be a known problem.

I'm going to leave this issue open for further investigation. Perhaps there is some header that Microsoft Outlook requires to ensure UTF-0 encoding.

@PrinceVarshney
Copy link
Author

Hey @thinkingserious

I need to have some workaround for the same, as most of the clients of our projects are using Outlook only.

@thinkingserious
Copy link
Contributor

Hello @PrinceVarshney,

I have added this to our backlog for further review.

@thinkingserious
Copy link
Contributor

Hi @PrinceVarshney,

Can you please try:

attachments.setFilename("=?utf-8?Q?Pris=20og=20oppgj=C3=B8rsvilk=C3=A5r.pdf?=");

Thanks!

Elmer

@PrinceVarshney
Copy link
Author

Hi @thinkingserious

Will try this and will inform you regarding the same.

Thanks!!

@PrinceVarshney
Copy link
Author

Hey @thinkingserious

This is not working. This is giving =utf-8QPris=20og=20oppgj=C3=B8rsvilk=C3=A5r.pdf

Thanks

@thinkingserious
Copy link
Contributor

Hello @PrinceVarshney,

What version of Outlook are you using?

@thinkingserious
Copy link
Contributor

@PrinceVarshney,

Can you email me with your Outlook email address so I can try sending a test to you?

@PrinceVarshney
Copy link
Author

@thinkingserious
version of outlook : 14.0.7177.5000

@PrinceVarshney
Copy link
Author

@thinkingserious
I have sent you a mail

@PrinceVarshney
Copy link
Author

@thinkingserious

Hey Its working

I attached this MimeUtility.encodeText("string", "UTF-8", "Q")
while setting the attachmentName :

mail.setAttachmentName(MimeUtility.encodeText("Pris og oppgjørsvilkår.pdf", "UTF-8", "Q"))

First we have to encode it as per Q-encoded
Thanks

@thinkingserious
Copy link
Contributor

@PrinceVarshney,

That's awesome and thanks for sharing the solution! I'm going to keep this ticket open so that we can add this to the SDK.

For your efforts, we would like to offer you some swag. Please fill out this form for us :)

@PrinceVarshney
Copy link
Author

@thinkingserious

Thank you !! Will fill the form once outside office network :)

@thinkingserious thinkingserious added type: community enhancement feature request not on Twilio's roadmap and removed type: question question directed at the library labels Apr 29, 2017
@thinkingserious thinkingserious added the difficulty: medium fix is medium in difficulty label Oct 1, 2017
@thinkingserious
Copy link
Contributor

Since there has been no activity on this issue since March 1, 2020, we are closing this issue. Please feel free to reopen or create a new issue if you still require assistance. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: medium fix is medium in difficulty status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap type: twilio enhancement feature request on Twilio's roadmap
Projects
None yet
Development

No branches or pull requests

3 participants