Why dose my mail lose some part of the content while being sent? - email

My code sends an email with received values.
My code:
self.alert = email.message.EmailMessage()
self.alert['Subject'] = my_subject
content1 = ''
content2 = 'ABCDEFGHIJ1ABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJ'
self.alert.set_content(content) #content1 or content2
self.alert['From'] = my_from
self.alert['To'] = my_to
self.smtp.send_message(self.alert)
(content1 is six consecutive 가나다라마.
In any reason, I cannot type it in the above code block.. The site rejects to post that. Maybe it's not English..?)
When I give content1, the mail of the receiver shows only some part of the content.
가나다라마가나다라마가나다라마가나다
On the other hand, for content2, even though the length is much longer than content1, it shows all the characters in the received email.
content1 contains Korean.
Does the language have to do with this problem?
When I do the same thing on my Mac, it sends Korean well.
But this problem happens when I use a remote server.
Any thought is appreciated :)

I still don't know why, but after I tried with python3.6, the issue was gone.

Related

Google Script: get content of an email answer without the original email

I am having troubles dealing with the emails that are answers to emails I sent myself. Indeed, when I use the method 'getPlainBody' to get the content of the email, I always get a text containing the message I want AND my original message. Moreover, the format is never the same, depending on the email client of the other person, I guess.
Some examples to illustrate this:
Hello,
This is my answer to your email.
Best regards
On Wed, Jul 12, 2017 at 10:02 AM, Bastien <bastien#example.org> wrote:
> Hi,
>
> This is the original email I sent you.
> Bastien
Or this:
Hello,
This is my answer to your email.
Best regards
From: bastien#example.org [mailto:bastien#example.org]
Sent: Wednesday, July 12, 2017 6:49 PM
To: someone <someone#example.com>
Subject: this is the original subject
Hi,
This is the original email I sent you.
Bastien
I would like to retrieve only this part:
Hello,
This is my answer to your email.
Best regards
I also have emails many different languages, so the information separating the original message and the answer can be written in any language, so it is a bit complicated to detect it programmatically for any language.
I am sure Gmail knows how to do that, because in the Gmail interface it only shows the part of the email that I want, and automatically hides my first email. I just do not know if there is a way to extract the message using Google Script.
Bastien,
I did resolve in a not elegant but fairly stable way getting the body and taking advantage of the Gmail knows situation, i.e. looking for the tag <div class="gmail_quote"> which is the [...] showed by GMail.
In those cases where [...] is not the case (e.g. mail sent by microsoft mail) the first <div> sometimes do the trick.
You will see two others attempts harvested on errors saw since the first implementation of this code (about a year ago). In my case the senders universe is quite small so this cheesy solution works nice.
Good luck.
mRtaU = mails[j].getBody();
mRta = mRtaU;
mRta = mRta.substring(0,mRta.toLowerCase().indexOf('<div class="gmail_quote">'));
if( mRta == '' ){
mRta = mRtaU;
if( mRta.slice( 0, 5 ) == '<div>' ){ //case Microsoft try I...
mRta = mRta.substring(0,mRta.toLowerCase().indexOf('</div>'));
}else{
if( mRta.slice( 0, 2 ) == '<p' ){ //case Microsoft try II...
mRta = mRta.substring(0, mRta.toLowerCase().indexOf('</p>'));
}else{
mRta = mRta.substring(0,mRta.indexOf('\n')); //last try, a crlf could split the answer from original (yeap, no crlf in html but...)
}
}
}
mRta = mRta.split('<br>').join('\n').replace(/<\/?[^>]+(>|$)/g, "");

Gmail conversation grouping (threads) causing HTML email format issues

I have an HTML email that I send to my users. It looks great in all major Web, Desktop, and Mobile clients even Gmail, EXCEPT when the email is included as part of a "conversation" in Gmail. In that case, some of the table background colors don't show, the text alignment is wrong, etc. Is there a way to prevent this?
Make sure your messages have different subject lines, that'll prevent them from being in a conversation. Or, if just testing, leave the subject line blank.
Tested answer: Change the sender of your email by inserting a random number. So instead of sending from foo#bar.com, send from foo+1#bar.com. Functionally, these are the same email address (replying will send to the same person).
In ES5:
randomNumber = Math.floor(Math.random()*100).toString();
from = 'Foo <foo+' + randomNumber + '#bar.com>';
In ES6:
randomNumber = Math.floor(Math.random()*100);
from = `My Company <foo+${randomNumber}#bar.com>`;

separate email from original email using perl

When people email each other, they generally include the original email in their reply to a sender, adding a little more information each time to the email. Each email client seems to have a different way of adding the original email to a reply.
I need to parse email arriving at our mail server and try and extract the new part of the message, and I'm wondering if there is a sensible way to strip this appended (or prepended) information (the "original message") and just get the new information in a mail body? I believe sadly, that there is no encoding, the original email is simply added to the new message, but I thought I'd check with the experts?
thanks.
No, there is no simple, straightforward algorithm to separate quoted or forwarded text from new content. Quoting and forwarding are poorly standardized and different conventions have existed at different times.
Having said that, e.g. Google's Gmail succeeds fairly well in practice. With enough samples, you can clearly come up with reasonable heuristics.
Good indicators for quoted material are forwarded (pseudo-) headers and indented text, perhaps with a quote indicator along the left margin before the quoted text. You occasionally see outdents as well.
Traditionally, on Usenet in the early 1990s, people would use different, unique quoting styles.
: ~ | This seems to be the original.
: ~ This is the first reply.
: This is the second reply.
This is the third reply, quoting the
previous three messages in sequence.
Around 1995, both clients and standardization initiatives by and large converged on "wedge" quotes;
> >> This seems to be the original.
> > This is the first reply.
> This is the second reply.
This is the third reply, quoting the
previous three messages in sequence.
Then along came Microsoft and ruined it all. I suppose that top quoting makes sense in some corporate settings where you quickly need to collect all the background from a thread to a new participant, but even for that purpose it's a horrible abomination.
This is the third reply, quoting the
previous three messages in sequence.
---- Begin forwarded message ----
From: Him [smtp:bogus]
To: His Friend
Subject: VS: Re: Same as on this message
Date: nothing machine-readable
This is the second reply.
---- Alkuperäinen viesti ----
Lähettäjä: His Friend [smtp:poppycock]
Saaja: Some Guy
Aihe: Re: Same as on this message
Päivämäärä: olisiko eilen ehkä
This is the first reply.
----- Original message ----
From: Somebody Else [smtp:mindless]
To: Some Guy
Subject: Same as on this message
Date: like, the day before
This seems to be the original.

sendmailR: Submit encoded message to local SMTP server

I need your help in order to send email message that includes text in Greek, from within R, using the function sendmail {sendmailR}.
I tried using the function iconv, like that but it didn't work
subject <- iconv("text in greek", to = "CP1253")
sendmail(from, to, subject, msg, control=list(smtpServer="blabla"))
The mail arrives immediately but the greek characters are unreadable. Any ideas?
EDIT
Another question that came up:
The second argument to accepts one recipient. What if want to send it to more than one? (I think 'll try sapply ing the sendmail function to a vector of recipients) - Ok, that worked. However, I'm not completely satisfied because each one of the recipients has no way to know who else has received the message.
Mail client won't be able to understand any encoding without Content-Type: charset=..., so you must add it:
msg<-iconv("text in greek", to = "utf8");
sendmail(from, to, subject, msg,
control=list(smtpServer="blabla"),
headers=list("Content-Type"="text/plain; charset=UTF-8; format=flowed")
);
that is for UTF8 (which I believe should be used), for CP1253:
msg<-iconv("text in greek", to = "CP1253");
sendmail(from, to, subject, msg,
control=list(smtpServer="blabla"),
headers=list("Content-Type"="text/plain; charset=CP1253; format=flowed")
);
multisend by hidden copies can also be done with header magick, still I think sapply loop is a better idea -- then the user will see that the mail was send directly to her/himself.

CDO message: text attachment gets corrupted

I'm creating an email message using CDO object (and VB6, but that doesn't really matter).
With New CDO.Message
.To = "<address>"
.Subject = "Manifest test 8"
.Organization = "<company>"
.From = "<address>"
.Sender = .From
With .Configuration
.Fields(cdoSendUsingMethod).Value = cdoSendUsingPort
.Fields(cdoSMTPServer).Value = "192.168.0.4"
.Fields.Update
End With
With .AddAttachment("c:\import\customermanifestOURACCOUNT11122008110032.dat")
.Fields(cdoContentDisposition).Value = "attachment; filename=""Consignor.dat"""
.Fields.Update
End With
.Send
End With
As you can see, the message is empty and contains an attachment that I rename in the email.
The attachment is an ASCII text file, fixed-width, that contains some output from our systems, one record per line, separated with CRLF.
When the message gets sent, all CRs get stripped out the attachment, so the receiver gets a file that only has LFs and therefore is corrupted.
I tried to change ContentEncoding to 7bit and base64, didn't work.
I tried to set ContentMediaType for the attachment to text/plain, didn't work.
I tried to not rename the attachment after adding, didn't work.
The ContentMediaType for the attachment is set to application/octet-stream by default, so I can't figure out why (and by what) it gets changed in the first place.
If I execute .SaveToFile() on the attachment right after .Send(), it saves valid file on the disk.
Is this a problem in my code, or is it a mail server setting or something?
Ok, that was weird.
We used our gmail accounts to test that thing, more specifically, gmail web interface. We clicked attachments links to save reveived files. And the files were corrupted.
As soon as we instead tried some thick clients, it turned out to be fine. All files get download properly without any corruptions.
So I assume this is a bug in gmail web interface (as opposed to gmail POP3 interface).
I have not used CDO in a long time, but i remember having this issue in the past. By trying different things, we figured that if there was any content in the body of the message the attachments were sent properly.
Weird, i know.
try it and let us know.
I just got this same trouble. I switched to Jmail and my CSV (text file) was now exactly like the original when I read it from gmail.
I compared the original message (in Gmail, option - view original message) and discovered that with CDO.Message, the attachment is not encoded really well, it is kept in text format, and the mail client do what he wants with it. With Jmail, the message is encoded in Base64 so it is kept in its original state from the start to the end. So, be careful when using CDO.Message with text file attachments! Try using Jmail (free) instead.
CDO.message: Content-Transfer-Encoding: quoted-printable
Jmail.message: Content-Transfer-Encoding: base64