How to send an email with query output result as attachment from Data Factory? - azure-data-factory

I have a data into the SSMS table that I need to send it as an email attachment using data factory. any suggestion to set up a pipeline such way so I can query the data from the table and attach that output and send it in the email would be appreciate.
I tried using logic APP to send an email , I am able to send an email but I was not able to find out the way I can attach the query output data as an attachment in that email , 1st have a lookup activity to get the data from the table then I have used web activity to set the trigger to send an email. inside the web activity I have used Logic app URL , post as method ,
BODY : { "message" : "#{activity(Lookup1').output}", "DatafactoryName" : "#{pipeline().DataFactory}", "pipelineName" : "#{pipeline().PipelineName}","receiver" : "#{variables('receiver')}"
I have declare variable called receiver to store email ids.

To send an Output of lookup activity as an attachment follow the below procedure:
In logic app For the Send Email (V2) action, customize how you wish to format the email, using the properties and to add attachment select Attachment from Add new parameter dropdown give Attachment name you want and add Attachment Content as message from Dynamic content.
For the Body, enter the following JSON:
{
"message" : "#{string(activity('Lookup1').output.value)}",
"dataFactoryName" : "#{pipeline().DataFactory}",
"pipelineName" : "#{pipeline().Pipeline}" ,
"receiver" : "#{pipeline().parameters.receiver}"
}
Output:

Related

How to send activity output as email attachment in logic app

I have an ADF pipeline, I want to send the output of my activity as an email attachment in the logic app.
I have a lookup activity followed by a For each activity and an Inside For each activity I have a web activity to call the logic app.
I want to send the output of the lookup activity as an email attachment to the logic app. I am not able to think about this integration part.
Create Logic app event trigger with HTTP and Outlook.
Inside HTTP request is received:
Copy HTTP POST URL
Request Body JSON Schema
{ "properties": { "dataFactoryName": { "type": "string" }, "message": { "type": "string" }, "pipelineName": { "type": "string" }, "receiver": { "type": "string" } }, "type": "object" }
POST Method
Send an Email
Connect Your outlook email .
Use HTTP POST URL as shown in step1
Create parameter name receiver
Add dynamic this content
s
{
"message" : "This is the row from lookup item #{item().customerID},#{item().gender},#{item().SeniorCitizen},#{item().Partner}.",
"dataFactoryName" : "#{pipeline().DataFactory}",
"pipelineName" : "#{pipeline().Pipeline}",
"receiver" : "#{pipeline().parameters.receiver}"
}
Pipeline successfully executed and got the output:
There is no direct or easy way to send email attachment from ADF.
But as a workaround first you will have to save the output of your lookup activity to a file and then follow the approach described in this video by a community volunteer where logic apps come into play to send the lookup activity output data file as an attachment. How To Send File as Attachment From Azure Data Factory - Azure Data Factory Tutorial 2021
In order to save the lookup output data to a file you can follow this approach: Get Output of lookup activity in a file

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)

Odoo14: Send an email through code using a recordset in the template

Using a scheduled task, I need to send an email which will inform on the status of open tasks. After getting the recordset correponding to my search, I found how to load the template and send the email:
mail_template = self.env.ref('test_email.email_template')
mail_template.send_mail(self.id)
But I only got access to the current record in $object. I would like to be able to pass the recordset to the template and loop over it.
You can use the context to "transport" data into the mail rendering:
mail_template.with_context(my_recordset=my_recordset).send_mail(self.id)
In your mail template just use ctx:
%for record in ctx.get('my_recordset', []):
<div>${record.my_attribute}</div>
%endfor

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

text email template is not coming in the Mail

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.