Exceeding maximum subject length using message.forward - google-apps-script

I have searched the site, and the web, but have had no joy.
I have a google apps script attached to a spreadsheet that (among other things) forwards emails with a given label to a given email address. I recently sent an email with a very long subject line, and the script has started failing on the following line of code:
msgsToStore[l].forward(emailAddress);
The error I receive is "Argument too large: subject"
The subject of the original email is 283 characters. Forwarding the message within the gmail web interface works without difficulty, adding "Fwd: " to the beginning as you would expect. The subject contains an ampersand, but is otherwise not unusual.
I need something I can use other than .forward, or some way of modifying the message object before forwarding it, but I can't find any documentation as to what the maximum size is.
Any help is greatly appreciated.

Trim the subject:
trimmed_subject = msgsToStore[l].getSubject().substring(0, 250)
msgsToStore[l].forward(emailAdress, {
subject: trimmed_subject,
});
More details: https://developers.google.com/apps-script/reference/gmail/gmail-message#forward(String,Object)

Related

Odoo/OpenERP - send all mails from same adress

We have set up Odoo 8 as a multi-user helpdesk tool, which creates a new project issue for each incoming mail. Incoming and outgoing servers are configured correctly and system parameters are set to
mail.catchall.domain: company.tld
mail.catchall.alias: helpdesk
mail.bounce.alias: bounce
The problem now is that every time a user comments the mail thread to answer the original issue creator, a new mail is generated with header
FROM: [user]#company.tld
TO: [followers]
REPLY-TO: helpdesk#company.tld
Which is totally fine but leads to a sending failure due to our SMTP configuration. To get around this we want to achieve that all outgoing E-Mails are sent from the same specified address, like helpdesk#company.tld, no matter which user response to the thread.
How do we achieve this?
I had specific issue when I was working on Odoo 8 and I found fix but its not recommended action from developer view, because changing odoo source code is not recommended and changes can be lost.
So what I did was to change email from address to real email from address. Yes it's weird but that's how Odoo works. Odoo is always sending from one specific email address and changes email from to user email address, but if you will look at email carefully you will notice that real sender is always same.
The fix is changing this line
smtp_from = message['Return-Path']
to this line
smtp_from = tools.config.get('email_from')
in openerp/addons/base/ir/ir_mail_server.py file.
PS I don't like this solution.

How do I keep "MailApp.sendEmail" emails with the same subject threaded?

I've written a script that sends an hourly email to me using:
MailApp.sendEmail("john#doe.com", "Status Update", currentStatus);
My only gripe is that every message I get is treated as a separate thread, despite the subject lines all being the same. I'd prefer if all were threaded so I can see the stream of messages in one place.
Is there any way to have new status messages appended to the same thread?
Will this require using GMailApp functions instead?
EDIT (2016-08-26): I have solved my problem using the following method/workaround:
Include a unique "marker" somewhere in the status message. I use a static UUID that I generated online.
Use GmailApp.search() to find the thread with the status message(s) by looking for the unique marker.
Use GmailApp.reply() to add a new status message to the thread.
This keeps all the status messages together as desired. Perhaps there's a more elegant way to do this but this works...

EWS Body of Email coming back empty?

We are in the process of converting a batch job that processes our bounced emails that we send. We are switching from Redemption to EWS (just upgraded to Exchange 2010 from Exchange 2003). As you know bounced emails come in different forms. I have been able to work through all the test case emails i've got except for the ones that come in the form of:
Your message did not reach some or all of the intended recipients.
Subject: Hello
Sent: 4/01/2012 8:16 AM
The following recipient(s) cannot be reached:
hi#foo.com on 4/01/2012 8:19 AM
The e-mail system was unable to deliver the message, but did not report a specific reason. Check the address and try again. If it still fails, contact your system administrator.
smtp.mydomain.com #5.0.0 smtp; 5.3.0 - Other mail system problem 554-"delivery error: dd This user doesn't have a foo.com account (hi#foo.com) [-5] - mail.foo.com" (delivery attempts: 0)>
This is what is displayed in outlook. When i read the email with EWS the Body is empty. I need to look at the information above when i get the email with EWS. The emails have an attachment (which is the original email) though it doesn't look that way in outlook. I've tried to look at almost all the properties that comes back from EWS and have yet been able to find the text above. Redemption allow you to look at this info using ReportText. What we are specifically looking for is the email error delivery code. We do different things based on this code.
Edit: To be clearer the Body Property on my other test cases isn't empty. I'm loading the emails like:
Dim emailPset = New PropertySet(BasePropertySet.FirstClassProperties)
emailPset.RequestedBodyType = BodyType.Text
Dim f = EmailMessage.Bind(email.Service, email.Id, emailPset)
Update1: After some research it looks like i need to be able to read the Recipients table of the message in the PR_NDR_STATUS_CODE & PR_REPORT_TEXT fields. Still searching if there is a way to do this in EWS.
We were able to get enough info the
smtp.mydomain.com #5.0.0 smtp; 5.3.0 - Other mail system problem 554-"delivery error: dd This user doesn't have a foo.com account (hi#foo.com) [-5] - mail.foo.com" (delivery attempts: 0)>
part which is what we needed by telling the object to load the MIME content.
Definitely not the most straight forward API to use but hopefully we don't hit any more hickups.

using boto and SES, emails with links don't go through

Something really weird is going on with boto and Amazon SES. I've tested this at-least 50 times: Sending an email using:
conn = SESConnection(accessKey, secretKey)
conn.send_email(source=fromEmail, subject=subject, body=body, to_addresses=toAddress, cc_addresses=cc_addresses, bcc_addresses=bcc_addresses, format='html', reply_addresses=None, return_path=None)
works as long as the body is regular text. A soon as body contains a link, like "127.0.0.1", the email doesn't go through. send_email doesn't return an error, it just doesn't go through and I can't tell why. The only exception is if the link is the very last piece of text in the body. So, body = "go to 127.0.0.1" will get into the recipients' inboxes, but body = "go to 127.0.0.1 and click on the link" will not work.
Weird, right? What's going on?
EDIT, several wasted hours later:
So after killing several hours on this, I don't know exactly what the problem is, but I know that it doesn't have to do with Boto or Amazon SES. I sent the exact same email to a different address and had no problems with it. Now this is seriously weird and stupid. The email used for my school runs on Google apps and exhibits the wacky behavior described above. My personal email is plain old gmail and doesn't have this issue at all. I even checked the spam folder for my school email and it's not there.
So that's it, the difference between having an "http" and an "https" in the body of the email, and only for certain email accounts. No errors, just a lost email. WTF?

EntLib 5 Email Subject Line Edit?

I am trying to change the subject line of email sent by Enterprise Library 5. I don't mean changing the subject line Starter/Ender (as seen in http://entlib.codeplex.com/discussions/69689?ProjectName=entlib), I want to change the actual Subject text, which is not the same as the Logger's Message Title.
All ideas appreciated.
Thanks.
Looking at the source for EmailMessage in Enterprise Library 5 the subject is generated by
string sendToSmtpSubject = header + logEntry.Severity.ToString() + footer;
If you need to have complete control of the subject line in your email message you will need to extend the existing EmailTraceListener to include your added functionality. (or simply modify the code and use your custom build of EntLib in your application).