Hi all,
in my workflow I want send an email to a specific mail. But I no idea how I can do this.
I create this code
import { axios } from "@pipedream/platform"
export default defineComponent({
props: {
gmail: {
type: "app",
app: "gmail",
}
},
async run({steps, $}) {
console.log(this.gmail.$auth);
return await axios($, {
url: `https://www.googleapis.com/oauth2/v1/userinfo`,
headers: {
Authorization: `Bearer ${this.gmail.$auth.oauth_access_token}`,
},
})
},
})
But how I can add recipient and send email?
pi
(Pi)
August 14, 2024, 2:58pm
2
Hi @pls_lite_development ,
You should visit Pipedream for the latest pricing, but I’ll do my best to answer.
To send an email using the Gmail API in your Pipedream workflow, you can use the Send Email action provided by Pipedream. Here is an example of how you can modify your existing code to send an email:
import { axios } from "@pipedream/platform";
export default defineComponent({
props: {
gmail: {
type: "app",
app: "gmail",
},
to: {
type: "string",
label: "Recipient Email",
},
subject: {
type: "string",
label: "Email Subject",
},
body: {
type: "string",
label: "Email Body",
},
},
async run({ steps, $ }) {
return await axios($, {
method: "POST",
url: `https://gmail.googleapis.com/gmail/v1/users/me/messages/send`,
headers: {
Authorization: `Bearer ${this.gmail.$auth.oauth_access_token}`,
"Content-Type": "application/json",
},
data: {
raw: Buffer.from(
`To: ${this.to}\nSubject: ${this.subject}\n\n${this.body}`
).toString("base64"),
},
});
},
});
Explanation
Props : Added to, subject, and body props to accept the recipient email, subject, and body of the email.
API Request : Modified the API request to use the Gmail API’s send endpoint.
Email Format : Constructed the email in the required format and encoded it in base64.
Steps to Use the Component
Search for the Gmail app in the Pipedream UI.
Select the Send Email action .
Connect your Gmail account .
Fill in the recipient email, subject, and body .
Test the action to ensure it works as expected.
This should enable you to send an email to a specific recipient using your Pipedream workflow. If you need further assistance, please visit Pipedream .
I’m a bot powered by Pipedream and GPT-4. I’m still learning, so please double-check my answers and code! Learn how to build your own .
1 Like
Thx, And how can I force the email to be displayed in html format?
andrew
(Andrew)
August 16, 2024, 12:24pm
4
Hi @pls_lite_development , have you tried our built-in Gmail - Send Email action? You can select html in the Body Type prop.
Hi, thx, I prefer do this in nodejs.
In found the fix. Just add “Content-Type: text/html”