Skip to content

Attachment Name does not show Norwegian Characters #19

Closed

Description

@PrinceVarshney

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!

Activity

  1. thinkingserious commented on Mar 15, 2017

    @thinkingserious
    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

  2. added
    status: help wanted
    type: question
    on Mar 15, 2017
  3. PrinceVarshney commented on Mar 15, 2017

    @PrinceVarshney
    Author

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

  4. thinkingserious commented on Mar 15, 2017

    @thinkingserious
    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

  5. PrinceVarshney commented on Mar 16, 2017

    @PrinceVarshney
    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

  6. thinkingserious commented on Mar 16, 2017

    @thinkingserious
    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("dx@sendgrid.com");
        String subject = "Hello World from the SendGrid Java Library";
        Email to = new Email("elmer.thomas@sendgrid.com");
        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.

  7. PrinceVarshney commented on Mar 16, 2017

    @PrinceVarshney
    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. ?

  8. thinkingserious commented on Mar 16, 2017

    @thinkingserious
    Contributor

    @PrinceVarshney,

    Yes, I am using the latest version 3.1.0.

    Can you check the encoding on your source code editor?

  9. PrinceVarshney commented on Mar 16, 2017

    @PrinceVarshney
    Author

    @thinkingserious

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

    Whats the use of below line ?

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

  10. thinkingserious commented on Mar 16, 2017

    @thinkingserious
    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

  11. PrinceVarshney commented on Mar 16, 2017

    @PrinceVarshney
    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.. ?

  12. thinkingserious commented on Mar 16, 2017

    @thinkingserious
    Contributor

    I'm not sure.

    Can you please try sending your test email to elmer.thomas@sendgrid.com?

  13. PrinceVarshney commented on Mar 16, 2017

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

  14. thinkingserious commented on Mar 16, 2017

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

  15. 11 remaining items

  16. PrinceVarshney commented on Mar 17, 2017

    @PrinceVarshney
    Author

    @thinkingserious

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

  17. added
    type: community enhancement
    and removed
    type: question
    on Apr 29, 2017
  18. thinkingserious commented on Mar 11, 2021

    @thinkingserious
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    difficulty: mediumstatus: help wantedtype: community enhancementtype: twilio enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions