sendgrid/sendgrid-java

Sent Mail as text/html with html string encoded with utf-8 shows symbols

NSTSA1 opened this issue · 2 comments

Hi! I am trying to send a Email with content-type text/html. The content is read from a local html-file, which is encoded with UTF-8. The outcome in the mail looks like the following picture.

image

Code Snippet

String content = getContentOfHtmlTemplate();
Mail requestMail = createSendGridMail("xxxx@xxxxx.xx", mailRecipient, "Betreff", "text/html", content);
Request request = createSendGridRequest(requestMail);
SendGrid sendGridClient = createSendGridClient();		
Response response = sendGridClient.api(request);
public String getContentOfHtmlTemplate() {
	String filePath = new File("").getAbsolutePath() + "/src/main/resources/xxxxxx/xxxxxxxxxxxx.html";
		StringBuilder contentBuilder = new StringBuilder();
		try {
		    BufferedReader in = new BufferedReader(new FileReader(filePath));
		    String str;
		    while ((str = in.readLine()) != null) {
		        contentBuilder.append(str);
		    }
		    in.close();
		} catch (IOException e) {
			System.out.println("Error"+  e);
		}
		String content = contentBuilder.toString();
		return content;
	}

Here is also the meta-tag in my local html file.

<meta http-equiv="Content-Type" content="text/html;" charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" /><meta http-equiv="X-UA-Compatible" content="IE=edge" />

How can I configure SendGrid to send that html-template with UTF-8, so these symbols do not appear?

@NSTSA1 I don't quite follow. What's the desired output? Sendgrid's backend automatically encodes the body with whatever encoding is being passed to them which is utf-8 in this case.

Closing due to inactivity. Please open a new issue if you still need help.