ASPEmail with UTF-8 produces scrambled characters - utf-8

Can anybody tell me, why this code is not working?
The mail gets sent, but the characters are scrambeled up.
"日本語" becomes "日本語"
"テスト 日本語 äöü" becomes "テスト 日本語 äöü"
<%
Session.CodePage = 65001 ' UTF-8 code
%>
<!DOCTYPE html>
<html>
<head>
<title>MAIL TESTER</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<%
strSubject = "日本語"
strBody = "テスト 日本語 äöü"
Set objEmail = Server.CreateObject("Persits.MailSender")
objEmail.Host = "..."
objEmail.From = "..."
objEmail.FromName = "..."
objEmail.AddAddress "..."
objEmail.Username = "..."
objEmail.Password = "..."
objEmail.CharSet = "UTF-8"
objEmail.ContentTransferEncoding = "Quoted-Printable"
objEmail.IsHTML = True
objEmail.Subject = objEmail.EncodeHeader(strSubject, "UTF-8")
objEmail.Body = strBody
objEmail.Send
Set objEmail = Nothing
%>
MAIL SENT.
</body>
</html>

I had to add the following code on all the pages:
Session.CodePage = 65001
Response.Charset = "UTF-8"
or
Response.CodePage = 65001
Response.Charset = "UTF-8"
and then in notepad++, I had to make sure that the files are saved with the "Encode in UTF-8". My pages were saved as "Encode in UTF-8 without BOM". I don't know why they were saved like that, but that's how it was.

Related

Xamarin.Forms UWP - Setting WebView.Source as HtmlWebViewSource Processes Scripts Twice

In Xamarin.Forms UWP, if I have a WebView whose Source property is set to type UrlWebViewSource, it works as expected. BUT, if the Source property is set to type HtmlWebViewSource where the Html property is set as a string, then any <script>s in the HTML are processed twice.
I've set up a brand new Xamarin.Forms project, where the Content of the MainPage is set to a WebView in the code-behind. I've set it up so that I can easily switch out between setting the WebView.Source to UrlWebViewSource or HtmlWebViewSource:
public MainPage()
{
InitializeComponent();
var urlSource = new UrlWebViewSource { Url = "https://htmlpreview.github.io/?https://github.com/joelbyrd/external-resources/blob/master/storefulfillment/Printing/Packing/GNC-Pick.htm" };
var htmlStringSource = new HtmlWebViewSource
{
Html = #"<!doctype html><html lang='en'><head><meta charset='utf-8'><meta http-equiv='x-ua-compatible' content='ie=edge'><meta name='viewport' content='width=device-width, initial-scale=1'><title>Test</title></head><body><div id='log'></div><p>some text</p><script>document.getElementById('log').innerHTML += `<p>Testing</p>`;</script></body></html>"
};
var webView = new WebView
{
Margin = new Thickness(0, 20, 0, 0),
Source = urlSource, // displays as expected
//Source = htmlStringSource // <script>'s are processed twice, appending "Testing" to the body twice
};
Content = webView;
}
It's a problem that the scripts are executed twice, probably for several reasons, but for one, if I'm appending content to the body with JavaScript, then it will be appended twice - not what I want. Here's the test HTML code I'm using:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Test</title>
</head>
<body>
<div id="log"></div>
<p>some text</p>
<script>
document.getElementById('log').innerHTML += `<p>Testing</p>`;
</script>
</body>
</html>
When I set the WebView.Source to type UrlWebViewSource, and set the Url property to "https://htmlpreview.github.io/?https://github.com/joelbyrd/external-resources/blob/master/storefulfillment/Printing/Packing/GNC-Pick.htm", I get the following expected output:
BUT When I set the WebView.Source to type HtmlWebViewSource, with the Html property set to the string above (spaces taken out and properly escaped), I get the following:
You can see that "Testing" has been added to the body twice. This only happens in UWP, so I suspect it's a bug. Can anyone tell me what's going on here, and if there's a workaround?

Recove data from xml file with ruby for manipulating

i have a problem. I must recover the data from a xml file inside my print machine becouse i want recove number of copy each day but i can see only total copy from start day of machine.
My script must recover from xml file the total copy day by day and with my manipulition the script subtracts the number each day.
I have alredy try use my little script like follow
require 'net/http'
require 'uri'
uri = URI.parse( "http://192.168.1.80/wcd/system_counter.xml" )
params = {'q'=>'cheese'}
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.path)
request.set_form_data( params )
# instantiate a new Request object
request = Net::HTTP::Get.new( uri.path+ '?' + request.body )
response = http.request(request)
puts response.body
but when i try with other html page i have correctly response and i can see the code of page with my page i have this html page like response:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<HTML lang="en">
<HEAD>
<TITLE></TITLE>
<meta http-equiv="Expires" content="0">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta content="text/javascript" http-equiv="Content-Script-Type">
<noscript>
<meta http-equiv="refresh" content="0; URL=/wcd/js_error.xml">
</noscript>
</HEAD>
<BODY BGCOLOR="#ffffff" LINK="#000000" ALINK="#ff0000" VLINK="#000000" onload="location.replace('/wcd/index.html?access=SYS_COU');" >
</BODY>
</HTML>
When i go from browser i can see correctly number of copy.
What for your experiece the correctly mode for bypass this restriction with ruby code?
Thanks for all help.

Add inline images to spring email

How can I add, using localhost or Server, an image to be included in an e-mail that is sent via Spring with Thymeleaf?
This is my controllerMail.java:
final Map<String, String> inlineResources = new HashMap<String, String>();
Set<String> folderPath = new TreeSet<>();
for (File file : files) {
certificateFile = file.getCertificateFile();
String img = certificateFile.toString();
inlineResources.put("file", img);
}
inlineResources.put("img1", "/template/email/img/myImg.png");
And this my html mail:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title th:remove="all">Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body style="font-family:Trebuchet MS;">
<p>TEXT EMAIL</p>
<img style="max-width: 100%;" th:src="'cid:img1'" />
<img style="max-width: 100%;" th:src="'cid:file'" />
</body>
</html>
certificateFile return this path: /srv/dev/contents/jpgCache/certificate/10000/certificateName.jpg
So my mail.html is located on my project in src/main/resources in /template/email. In this case img1 is correct find on email (it is located in the same path /template/email/img) but file return this log error:
Invalid resource: /srv/dev/contents/jpgCache/certificate/10000/certificateName.jpg
Failed messages: javax.mail.MessagingException: IOException while sending message;
nested exception is:
java.io.FileNotFoundException: class path resource [/srv/dev/contents/jpgCache/certificate/10000/certificateName.jpg] cannot be opened because it does not exist
How i can fix this problem?
While the attachment of this file to email it works properly.
The solution for this problem is to use "file:" before the "pathImg":
String pathImg = certificateFile.toString().replace('\\', '/'); inlineResources.put("img", "file:"+pathImg);

Ruby Mechanize gem not following meta refresh

I have a Ruby 2.2 automation script that uses Mechanize to log in to Google Payments. When I try to access the url Mechanize stops on the meta refresh. The content of the page is:
<!DOCTYPE html>
<html>
<head>
<title>Redirecting...</title>
<script type="text/javascript" language="javascript">
var url = 'https:\/\/accounts.google.com\/ServiceLogin?
service\x3dbilling\x26passive\x3d1209600\x26continue\x3dhttps:\/\/payments.google.com\/
payments\/home%23__HASH__\x26followup\x3dhttps:\/\/payments.google.com\/payments\/
home'; var fragment = ''; if (self.document.location.hash) {fragment = self.document.
location.hash.replace(/^#/,'');}url = url.replace(new RegExp("__HASH__", 'g'),
encodeURIComponent(fragment));window.location.assign(url);
</script><noscript><meta
http-equiv="refresh" content="0; url='https://accounts.google.com/ServiceLogin?
service=billing&passive=1209600&continue=https://payments.google.com
/payments/home&followup=https://payments.google.com/payments/home'"></meta>
</noscript></head>
<body></body>
</html>
Here is the part of my script to get to the login screen:
#agent = Mechanize.new
#agent.follow_meta_refresh = true
page = #agent.get("http://payments.google.com/payments/home")
puts page.content
The page.content at the end only shows the above html, the meta refresh is not followed. Any suggestions on how I can follow that would be greatly appreciated.
Assuming the script isn't really reformatted like that:
url = page.body[/url = '(.*?)'/, 1]
page = #agent.get url

dompdf special characters

I'm having successful html-to-pdf conversions, but not with special characters.
Below is just a special character I'm trying to display, which displays in browsers on my Mac, when I put it simply inside an html document. (but not on my windows box)
<?php
require_once("../dompdf_config.inc.php");
$html = '€';
$dompdf = new DOMPDF(); $html = iconv('UTF-8','Windows-1250',$html);
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("contract.pdf");
exit(0);
?>
I keep getting a "?" (question mark) when the pdf is rendered.
I know there's been lots of issues documented with regards to special characters, but I thought I'd give this a try, with the code I'm actually using.
If DomPdf isn't a recommended html-to-pdf conversion tool, I'll take any other recommendations!
I have experienced problems with DOMPDF when converting an UTF-8 html page.
I simply solved the problem by adding
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Between < head > tag.
Maybe it could be an alternative if you set it with your encoding type.
IMPORTANT NOTE from comments below: don't use stream() and output() methods on the same pdf instance. If you do this wont work.
after trying all solutions on the net. I could solve without modifying the dompdf. the problem was on the html content. I just had to add the correct and appropriate HTML structure and setting the font of course . Tested on v0.6.0 and v0.6.1. here I leave the code
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="charset=utf-8" />
<style type="text/css">
* {
font-family: "DejaVu Sans Mono", monospace;
}
</style>
</head>
<body>your content ćčžšđ...</body>
</html>
DOMPDF Latin Turkish (Türkçe) char problem, my solution %100 Work.
Server requirenment control:
Char 'dejavu sans mono' (Turkish support) OR:
Step 1: dompdf_config.inc.php edit to
mb_internal_encoding('UTF-8');
def("DOMPDF_UNICODE_ENABLED", true);
Step 2: lib/fonts/dompdf_font_family_cache.dist.php edit to add code:
'futural' =>
array (
'normal' => DOMPDF_FONT_DIR . 'FUTURAL',
'bold' => DOMPDF_FONT_DIR . 'FUTURAL',
'italic' => DOMPDF_FONT_DIR . 'FUTURAL',
'bold_italic' => DOMPDF_FONT_DIR . 'FUTURAL',
),
Step 3: doqnload font files to copy lib/fonts folder.
Download font files Link http://www.2shared.com/file/k6hdky_b/fonts.html
Step 4: Your code Edit example:
require_once("dompdf_config.inc.php");
$html='<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style>
html{padding:-30px;}
body { font-family: futural; }
</style>
</head><body>';
$html.='ı İ Ş ş ç Ç ö Ö ü Ü ğ Ğ ÿ þ ð ê ß ã Ù Ñ È » ¿ İsa Şahintürk';
$html.='</body></html>';
if ( isset( $html ) ) {
if ( get_magic_quotes_gpc() )
$html = stripslashes($html);
$old_limit = ini_set("memory_limit", "16M");
$dompdf = new DOMPDF();
$dompdf->load_html($html,'UTF-8');
$dompdf->set_paper('a4', 'portrait');// or landscape
$dompdf->render();
$dompdf->stream("limitless.pdf");
exit(0);
}
End Finish PDF > example
http://limitsizbilgi.com/pdf/dompdf-chartest.pdf
Anything prior to 0.6.x has limited support for characters outside iso-8859-1 encoding. The Euro is supported in 0.5.x by using the appropriate Windows ANSI character code (€), but otherwise you have to jump through some PDF encoding hoops.
The 0.6.0 release has better support for "special" characters. The default encoding is based on Windows ANSI (one of the few recognized by the PDF 1.3 spec). You can enable better character support by loading a Unicode-based font and enabling Unicode in dompdf and specifying that encoding in your document.
The following should work in dompdf 0.6.0 or greater:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<p>€</p>
</body>
</html>
(or to be lazy just use the euro entity € in your test)
There is a document outlining the steps needed to enable Unicode support in DOMPDF.
Plus read this answer for an overview of how to load fonts.
You must use another character set. For example dejavu Sans Mono. Add your code
<style>
*{
font-family:"DeJaVu Sans Mono",monospace;
}
</style>
I also mentioned it in this video.

Resources