sendmailR: html and multilingual support - html

I use sendmailR (ver. 1.0-0) to create automated corporate mails. Inside the mail message I insert html code to produce tables. Finally, before sending, I convert the message to utf8 - since it contains multilingual characters, using
msg <- iconv(msg, to = "utf8")
After migrating to ver. 1.1-2 (in order to send mails with attachments), the contents of the mail cannot be read anymore. The text is unreadable and the html code is ignored. This is an example of the contents after upgrading:
για το μήνα Î”ÎµÎºÎ­Î¼Î²Ï Î¹Î¿ (ανά ÏƒÏ Î¼Î²Î±ÏƒÎ· και Î±Î¸Ï Î¿Î¹ÏƒÏ„Î¹ÎºÎ¬), έχουν ως εξής.<br><br> <b>Ανά ÎšÎ±Ï„Î·Î³Î¿Ï Î¯Î± και Î£Ï Î¼Î²Î±ÏƒÎ·</b><br>
<table style='border-collapse: collapse; border-color: rgb(136, 136, 136); border-width: 1px;' border='1' bordercolor='#888888' cellspacing='0'>
<tbody><tr>
<td style='text-align: center; width: 40px; height: 20px;'> Α.A.</td>
Do you suggest to continue using the initial version?
Thank you

Related

How to set text-wrap class in Chrome

I want use below code to enable line break for the cell.
Grid6Obj.getRowTemplate().setClass("text", "wrap");
But when I opened the page in chrome and it didn't work.
I debug the page and the html is like below.
<span id="aw36-row-0" class="aw-templates-list aw-text-wrap aw-grid-row aw-row-0 aw-rows-normal aw-alternate-even "><span id="aw36-row-0-start" class="aw-row-start " style="width:0px;"></span><span id="aw36-cell-0-0" class="aw-item-template aw-templates-cell aw-grid-cell aw-column-0 aw-cells-normal " style="border-right:1px solid #ccc;border-bottom:1px solid #ccc;" title="">123 456 678</span><span id="aw36-cell-1-0" class="aw-item-template aw-templates-cell aw-grid-cell aw-column-1 aw-cells-normal " style="border-right:1px solid #ccc;border-bottom:1px solid #ccc;" title="">12</span><span id="aw36-row-0-end" class="aw-item-template aw-grid-cell aw-column-space "><span id="aw36-row-0-end-box" class="aw-item-box "></span></span></span>
It set the class but the value "123 456 678" is still in one line. Is this because Chrome didn't suppose this class?Then what's the correct way to archieve it? Thx.
I did some research for you, there are 3 easy options. wrap your data in PRE tags
<PRE>
123
456
678
</PRE>
or in your aw.css file you could change the css on line 17
.aw-text-normal .aw-templates-cell, .aw-text-normal .aw-templates-text, .aw-text-normal .aw-templates-link, .aw-text-normal .aw-item-box {
white-space:nowrap;
}
Which is set to nowrap, changing this to pre will allow you to hard break your lines. Though this solution will change all cells to type PRE
.aw-item-box {
white-space:pre
}
Alternatively you could mutate your data to this:
"Line1 \r\n Line 2"

Get error "may be sending automated queries" in Google Drive API using Soup (Vala)

The Google Drive API at times returns a response of an HTML page with contents:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Sorry...</title>
<style>
body {
font-family: verdana, arial, sans-serif;
background-color: #fff;
color: #000;
}
</style>
</head>
<body>
<div>
<table>
<tr>
<td><b>
<font face=sans-serif size=10>
<font color=#4285f4>G</font>
<font color=#ea4335>o</font>
<font color=#fbbc05>o</font>
<font color=#4285f4>g</font>
<font color=#34a853>l</font>
<font color=#ea4335>e</font>
</font>
</b></td>
<td style="text-align: left; vertical-align: bottom; padding-bottom: 15px; width: 50%">
<div style="border-bottom: 1px solid #dfdfdf;">Sorry...</div>
</td>
</tr>
</table>
</div>
<div style="margin-left: 4em;">
<h1>We\'re sorry...</h1>
<p>... but your computer or network may be sending automated queries. To protect our users, we can\'t process
your request right now.</p>
</div>
<div style="margin-left: 4em;">See Google Help for
more information.<br /><br /></div>
<div style="text-align: center; border-top: 1px solid #dfdfdf;">Google Home
</div>
</body>
</html>
This happens when calling the https://www.googleapis.com/drive/v3/files/file_id endpoint with the aprameter "?alt=media" in order to get the content of the file.
I've not exeded any quota.
I don't get this error in other calls like https://www.googleapis.com/drive/v3/files?q=trashed = False .
The error ocurrs in an app that I've written in Vala (https://github.com/bcedu/VGrive). This app has been working well without getting this error. It started ocurring when Google changed the authentication, instead of using an access token in a query parameter, using an HTTP header instead. I made this changes and the problem was solved in some requests (like searching files as I mentioned) but I'm still getting the error when I want to download files.
I'm using the Google Drive api v3
I'm using the vala library Soup (a well known Gnome library https://developer.gnome.org/libsoup/unstable/) to make the requests. You can test the error with the following code:
public static int main(string[] args) {
// THIS DOESNT WORKS
string method = "GET";
string file_id = ""; // Some Google Drive File ID
string uri = "https://www.googleapis.com/drive/v3/files/%s?alt=media".printf(file_id);
string access_token = ""; // A valid acces_token
Soup.Session session = new Soup.Session ();
Soup.Message message = new Soup.Message (method, uri);
message.request_headers.append("Authorization", "Bearer %s".printf(access_token));
session.send_message (message);
// Response is stored in message.response_body.data
print("AUTOMATED QUERY ERROR:\n"+(string)message.response_body.data+"\n\n");
// THIS WORKS
uri = "https://www.googleapis.com/drive/v3/files?q=trashed = False and 'root' in parents";
session = new Soup.Session ();
message = new Soup.Message (method, uri);
message.request_headers.append("Authorization", "Bearer %s".printf(access_token));
session.send_message (message);
// Response is stored in message.response_body.data
print("THIS WORKS, SO TOKEN IS PASSES CORRECTLLY...\n"+(string)message.response_body.data+"\n");
return 0;
}
Run the test with:
valac --pkg libsoup-2.4 GoogleTest.vala
./GoogleTest
You will need to install:
libsoup-2.4
valac
I expect both a succesfull response or an autthentication error, but not an html page saying I'm making automated queries. It is an API, it is suposed to be used by apps and not only humans.
Am i missing something from google drive API? Do i have to do an additional step to pass the bearer token throught Soup?
As discussed in the comments the problem is being tracked in the google forums.
https://issuetracker.google.com/153717392
The issue there seemed to have been solved and OP has no longer problems using the API.

Give color to the text of HTML table body based on condition

I am sending out an html table in an email body using python. The html table consists of job status and I need to highlight the failed jobs in red and bold.
I have tried out different ways, including segregating failed and successful jobs and making seperate html tables and clubbing them at the end.But even after clubbing the second table had an extra border.
PFB the code I use for sending out html table.
import pandas
df = pandas.read_excel("C:\\"+os.environ["HOMEPATH"]+"\\Desktop\\Daily
Monitoring.xlsx", sheetname='Status Sheet')
import tabulate
html = """
<html>
<head>
<style>
table, th, td {{ border: 1px solid black; border-collapse: collapse; }}
th, td {{ padding: 5px; }}
</style>
</head>
<body><p>Hi All,</p>
<p> Kindly find below the monitoring result:  </p>
{table}
</body></html>
"""
col_list=list(df.columns.values)
html = html.format(table=tabulate.tabulate(df, headers=col_list, tablefmt="html",showindex=False))
What about rewriting the pandas table into string yourself?
table = ['<table>']
for row in range (5): #depends on your df size
table.append('<tr>')
for col in range (5): #depends on your df size
if df.iloc[row, col] == 'Failed'
table.append('<td class=\"failed\">Failed</td>')
else
table.append('<td>' + df.iloc[row, col] + '</td>')
table.append('</tr>')
table.append('</table>')
table = '\n'.join(table)
Haven't run that code, but hope you get that idea O:-)
In css there is a :nth child property you can use to realize it. I think
`table:nth-child(2) > td
{
color:red;
font-weight:bold;
}
`
Since you know which elements are affected, you have to repeat this multiple Times.
A much cleaner solution is to put the content of each table cell into a span, and give it a class.
Then write those classes and you are done.
Like
<table>
<tr>
<td><span class='importaint'>a</span></td>
<td><span class='importaint'>b</span></td>
</tr>
</table>

Thymeleaf special character conversion in Outlook

I have following html code (data coming in the variable as UTF-8)
<p style="margin: 0; font-size: 14px; font-family: Helvetica, Arial, sans-serif;">
Project Name: <span th:text="${projectName}">ProjectName</span>
</p>
Any special character that is in ${projectName} , for example : "Carol's" is getting converted to "Carol?s" in Outlook mail. Anyway to correct this in Thymeleaf ?

python extract email addresses from html file into another file

Basically what I'm trying to do is the following:
I've downloaded an HTML file and within this file contains a load of text and loads of different email addresses. What I would like to do is to only gather the email addresses from this file and input into 1 excel file using Python 3.4. Would anybody be able to help with that?
The HTML file looks like this:
<span style="display: none;"></span>
</td>
<td>Customer Care
- <a href="?team_search=Team%20Resera" >Team Resera</a>
<br>(team page & map)
</td>
<td>Berlin (BER2): Sesamestreet 11-12 </td>
<td>blablabla.blabla#blabla.com<br />
(jabber)
(xmpp)
</td>
<td>
work: 72496532 (Skype)<br />
</td>
This should get you started, from the example html it outputs
import re
file = open('example.html')
line = file.readline()
while line:
line = file.readline()
if bool(re.search(r'([\w.])+#([\w.])+', line)):
email = line.split('//',1)[-1]
email = email.split('\"',1)[0]
print email
file.close()
#outputs blablabla.blabla#blabla.com