text email template is not coming in the Mail - apex

As per the requirement I am sending a pdf file attachment to some email ids,I thought to include some static text to show in the email and i created one text template and added in the code ,but the text is not showing in the email.
here is the code
I used setTemplateId to show the template...
Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
attach.setContentType('application/pdf');
attach.setFileName(************************);
attach.setInline(false);
attach.Body = body;
Messaging.SingleEmailMessage mail = new
Messaging.SingleEmailMessage();
EmailTemplate et=[Select id from EmailTemplate where
name=:'CSPdfEmailtemplate'];
mail.setUseSignature(false);
mail.setToAddresses(Emailids);
mail.setTemplateId(et.id);//here i am giving the id of template
mail.setBccSender(true);

From the documentation a singleEmailMessage using a template needs to have the id of a contact, user or lead with setTargetObjectId(targetObjectId) so you will need to add that.

Related

Capture HTML Form Responses in Google Sheets and send a Confirmation Email to the Form Submitter

I want the script to send the created html email template email.html to the person who last submitted the form.
Below is the success message I get in the console:
Below is the actual email that is received by the person who submits the form:
The email.html is formatted correctly and appears perfectly when sent manually.
I hope this is reprex enough.
EDIT: Maybe it's easier if I include the code
function sendEmail () {
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var lr = ss.getLastRow();
var data = ss.getRange(lr,3);
var email = data.getValue();
var message = HtmlService.createTemplateFromFile('email');
var subject = "Test Subject"
GmailApp.sendEmail(email,subject, message);
}
It's not clear why you are using HtmlService.createTemplateFromFile, but from the image it's clear there at least one error, the script misses two methods:
HtmlService.HtmlTemplate.evaluate() to evaluate the Templated HTML
HtmlService.HtmlOutput.getContent() to get the HTML from the HtmlService.HtmlOutput object returned by the previous method.
Another option that looks to be an error is the use of GmailApp.sendEmail(string,string,string) method, as the third parameter should be a string to be used as the email plain text content. If you want to pass HTML, instead use GmailApp.sendEmail(string,string,string, Object)
Related
Emailing Google Sheet range (with or without formatting) as a HTML table in a Gmail message
Sending an email in HTML and plain with a Gmail Apps Script
Google script inject html into html email
References
https://developers.google.com/apps-script/guides/html
https://developers.google.com/apps-script/guides/html/templates
https://developers.google.com/apps-script/reference/gmail/gmail-app#sendEmail(String,String,String)

Odoo - How to send an email programmatically with the existing odoo email template?

I want to send an email programmatically with the existing odoo email template.
Call the send_mail method of template object with the id of the record to render the template.
template_id.send_mail(record_id, force_send=True)
force_send is used to specify to send the email immediately; otherwise, use the mail queue (recommended).
template_obj = self.env['mail.mail'].search([search your template)]
template_data['email_from'] = 'xyz#abc.com'
template_data['reply_to'] = 'xyz#abc.com'
template_data['subject'] = 'this is subject'
template_data['body_html'] = 'body'
template_id = template_obj.create(template_data)
template_id.send()
A sample code for Odoo 12:
template = self.env.ref('<module>.<template_id>')
template.send_mail(self.id, force_send=True)
where self.id is the record ID of the model referenced in the template's model_id field, which means its data will be used when rendering the template.

Salesforce send Email by Apex

I'm making by a requirement a code able to send an E-mail to an specific list of E-mails, due the fact that I must to include the attachments of the record I decided to use an apex class instead an e-mail alert. This object (A custom object ) must populate some fields in an email template with some of the record´s fields. I implemented the following code
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(lista);
mail.setTemplateId('00X21000000QR22');
//mail.setWhatId(idMinuta);
mail.setTargetObjectId('005d0000005NMIx');
mail.setSaveAsActivity(false);
List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
for (ContentVersion document: documents)
{
Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
efa.setFileName(document.Title);
efa.setBody(document.VersionData);
fileAttachments.add(efa);
}
mail.setFileAttachments(fileAttachments);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
I understood that to make the fields merge it´s necesary to use the WhatId method. In the related code, I have commented it because It generates an error (INVALID_ID_FIELD, WhatId is not available for sending emails to UserIds.)
My question is, if is it possible to do this with a custom object. I´m a little confuse with salesforce documentation beacuse it looks like the method supports a custom object, or maybe If I am forggeting something to include in the code.
If i keep the WhatID line commented, effectively the email is sent with the attachments and the Template but it is not populated.
I really need this kind of solution because the org have in this object at least 20 email templates, for me will be easier just to pass the Id of the template instead of makig a code with 20 different html codes for each situation
Thanks a lot
Please publish this question at Salesforce StackExcahnge https://salesforce.stackexchange.com/

How to set TO ADDRESS while sending an email in Hybris?

When user replies on a mail that he has received that should go to particular email id. I tried to give in DefaultEmailGenerationService.java but it didn't reflect.
Could any one suggest how it can be achieved?
Scenario 1:
How to change fromEmail Address of an email in Hybris?
As I mentioned in the comment if you want to set from emailAddress you can do that using Impex. Just find out what is your emailPage and set fromEmail and fromName.
Scenario 2:
How to set fix toAdress in Hybris for all email?
If you want to send all emails to some fix toAddress, in that case, you need to override email and displayName in respective *EmailContext of renderer template.
Let's just assume you want to override toAddress in customer registration flow. So here you need to find context class name form impex. Below are the renderer template for customer registration subject & body and CustomerEmailContext is the class name which will feed all data to this renderer.Now you just need to populate those data in init method of CustomerEmailContext.java
Scenario 3:
How to support multiple toAddress and attachments in Hybris?
To support multiple toAddress & fromAddress, ccAddresses, bccAddresses and attachments.
You need to create custom fields(toAddressList, ccAddresses etc) in
your *EmailContext and populate the value.
Override generate method of DefaultEmailGenerationService class.
Fetch your value from emailContext like emailContext.get("yourcustomFiled")
Modify createEmailMessage method in such way so you can pass all your custom fields(toAddressList, ccAddresses etc) to final DefaultEmailService
You can find detail post here

Sending HTML email from Joomla! component

I am developing a Joomla!3.0/3.1 component that allows people to book a golf lesson online. When they complete the booking and process paypal payment, I want to send them a receipt/confirmation email.
I can do this fine and send the information in html or plain text format. However I don't like the fact that I now have view (email content) data within my controller code.
Is it possible to have a sort of template view file which can be parsed and sent as the contents instead? or am I stuck with it in my code?
Thanks,
Chris
On admin side create a section for editing your email template with Joomla's default editor
you an create an editor on the backend and open an html file inside that, for changing the styles ,formats content etc for users.
keep your template file as an HTML file on server and email sending time something like below.
function send_mail_account_pages($email_title,$greeting_text,$subject,$email_content,$user_email){
$config = JFactory::getConfig();
$data['fromname'] = $config->get('fromname');
$data['mailfrom'] = $config->get('mailfrom');
$data['sitename'] = $config->get('sitename');
$path = JPATH_BASE."/email_tmpl/";
$fp = fopen($path."email_tmpl.html","r");
$fsize = filesize($path."email_tmpl.html");
$fcontent = fread($fp,$fsize);
fclose($fp);
$date_format = date("M.d, Y");
$fcontent = str_replace("{email_page_title}",$email_title,$fcontent);
$fcontent = str_replace("{date}",$date_format,$fcontent);
$fcontent = str_replace("{greeting_text}",$greeting_text,$fcontent);
$fcontent = str_replace("{email_content}",$email_content,$fcontent);
$fcontent = str_replace("{thanks_text}",THANKS_TEXT,$fcontent);
$return = JUtility::sendMail($data['mailfrom'], $data['fromname'], $user_email, $subject, $fcontent,1);
}
This way you can make admin users to give access to change the template styles make sure admin users do not edit the {place holders}.
Hope its helps..
Add a configuration field to your component of type textarea or editor, and let the user write the email template. You should explain which tokens are available or at least provide a default text, such as
Dear {USERNAME},
today I received {NUM_MESSAGES} messages on your behalf,
and your profile has been viewed {NUM_PROFILEVIEWS} times.
Then simply replace the {TOKENS} in your code with str_replace.