I had previously asked a question here. replace-cidimage-refrences-in-email-body The question came about because I am writing a basic email archiver/ archived email viewer.
I had saved the body using
IdMessage.Body.SaveToFile(FileName);
With the CID references in that body replaced with base64-encoded images, the resulting HTML displays in a TWebBrowser component when loaded from a blob field in my database. So I have an email viewer now.
The next requirement is to allow a reply to this email. I've added a TEdit above the TWebBrowser, where the UI user can type their single line reply, and I'm using some code to patch the html body to insert the reply line
Reply := '<p class=MsoPlainText>';
Reply := Reply + edReply.Text + '<br>';
Reply := Reply + '<br>-----Previous Message-----<br><br>';
Reply := Reply + '</p>';
before the first <p class=MsoPlainText in that body. This email, sent via IdSMTP, looks good, but Outlook isn't interested in displaying those inline base64-endoded images at all. I need to go back to where I started with this!
I would much like to do something like this:
When the original message is received, save it entirely using this
IdMessage.SaveToFile(FBasePath + 'raw_' + MessageID + '.html'); // works, and can be read by M$ Word
Then formulate that into a reply
IdMessage.LoadFrom(FBasePath + 'raw_' + MessageID + '.html');
IdMessage.Recipients.EmailAddresses := IdMessage.From.Address;
IdMessage.From.Address := repliersaddress;
But now the question is, how do I add the reply text to this html email.
IdMessage.InsertReply(edReply.Text); // would be great
Thanks
Related
I'm trying to send a bunch of mails to a list of contacts that I have saved in Google Sheets.
I copied the code to send the emails, but the emails that are sent aren't in the format that I need them in, and are getting converted to plaintext when being sent.
Any help on how to get around this issue?
P.S. My coding knowledge is nil, and I just copied the code from this website : https://productivityspot.com/automatically-send-emails-from-google-sheets/
The code I used is below:
function myFunction() {
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheet1=ss.getSheetByName('Sheet1');
var sheet2=ss.getSheetByName('Sheet2');
var subject = sheet2.getRange(2,1).getValue();
var n=sheet1.getLastRow();
for (var i = 2; i < n+1 ; i++){
var emailAddress = sheet1.getRange(i,2).getValue();
var name=sheet1.getRange(i,1).getValue();
var message = sheet2.getRange(2,2).getValue();
message=message.replace("<name>",name);
MailApp.sendEmail(emailAddress, subject, message);
}
You are facing a couple hurdles here. The only way you can send a formatted email is with an HTML body. HTML is the markup language used to display a webpage in your web browser, and it can also be displayed by email clients.
So in order to send a nicely (HTML) formatted email from Apps Script, you must first generate the HTML formatted body, then you must include is using the htmlBody parameter. You should also always include a plain text body (as you are now), just incase you have a recipient who doesn't receive HTML email (common for recipients with accessibility needs, using screen readers etc.)
There is no simple way to fetch formatted text from a spreadsheet cell as HTML, so you will need to either store your raw HTML in the spreadsheet, or figure out another location you can store and fetch the HTML body from. In my example below, I hardcode both the plain text and html bodies.
To send an HTML Body with MailApp, you need to use the additional "options" parameter, as shown below.
var html_message = '<body><h1>This is an HTML formatted body</h1><br><br><strong style="color:red">This can get pretty involved.</strong> Usually you would generate this html with some other tool that lets you nicely format your content and export it as HTML.</body>'
var plain_message = 'This is a plain text email body. It is is much simpler, with no special formatting, but usually it will include all the text from the html formatted message (above), since usually you want all your recipients to receive the same information'.
MailApp.sendEmail(emailAddress, subject, plain_message, {htmlBody: html_message});
See the advanced options specification here:
https://developers.google.com/apps-script/reference/mail/mail-app#sendEmail(String,String,String,Object)
I'd like to send and email with apple script to do like this :
hi,
here is the attachment file
[The attachment.pdf]
As you can see, it is a good attachment
Thanks
Bye
I know how to use applescript to send an email with attachment at the end of the message, but not between 2 sentences.
I tried something like this, but it doesn't work :
set _attachment to "Macintosh HD:Users:usr:Desktop:Form.pdf"
set msg to make new outgoing message with properties {visible:true, subject:"Here it is", content: "hi,
here is the attachment file"}
tell msg to make new attachment with properties {file name:_attachment as alias}
tell msg to add "As you can see, it is a good attachment
Thanks
Bye" as content
Thanks you all for your support.
Dam
Assuming we are talking about Apple Mail, you can specify the location of the attachment in the content of the message.
The text of body is passed instantly and the attachment is inserted afterwards.
set _attachment to (path to desktop as text) & "Form.pdf"
tell application "Mail"
set msg to make new outgoing message with properties {visible:true, subject:"Here it is", content:"hi,
here is the attachment file
As you can see, it is a good attachment
Thanks
Bye"}
tell content of msg to make new attachment with properties {file name:_attachment as alias} at after third paragraph
end tell
Description of the issue
I am sending emails in JavaScript with
message2 = message.replace("<br>", "\n")
GmailApp.sendEmail(address, subject, message2, {
cc: cc,
name: sendername,
htmlBody: message
});
…where message is a long string containing HTML tags.
On my Gmail account the email that is received contains a … in the middle to hide/extend the end of the message. The … correspond to newlines (<br>) but it seems to chose a newline randomly that will be used to split the message randomly.
I cannot get rid of all <br> of course. I always saw these … to separate the main part of the email from the signature. But in my case it just appears anywhere as for example right after the first line:
Question
How does GMail choses the “breakpoints” for shortening the message?
How can I avoid that GMail uses “breakpoints?”
Should I use something else than <br> to make newlines?
Currently , I'm recieving emails with my server(imap through spring framework)
the messages i recieve are of type MimeMessage.
lets say i now got a new email (X)
I would like to create a new MimeMessage (Y) that in it's body it will say that this email is in response (reply) to (X)
how can i do this?
p.s the (Y) message is going to be sent from a different SMTP url later on, so X and Y are not related.
thanks.
Simply create the new message and set its content to whatever you want - presumably something like...
"In Reply To:\n\n" + copied_text_content_from_received_message;
However, be aware that the inbound content might have various formats, including multipart (see JavaDoc for MimeMessage.getContent().
Start with the Message.reply method. Fill in the content of this new Message as suggested in the other answer here.
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.