Edits history of script submission #194 for ' Send Email (gmail)'

  • deno
    import { encode as base64UrlEncode } from "https://deno.land/[email protected]/encoding/base64url.ts";
    
    /**
     * @param user_id User's email address. The special value `me` can be used to indicate the authenticated user.
     */
    type Gmail = {
      token: string;
    };
    export async function main(
      gmail_auth: Gmail,
      to_email: string,
      subject: string,
      message: string,
      user_id: string = "me",
    ) {
      const token = gmail_auth["token"];
      if (!token) {
        throw Error(`
        No authentication token was found.
        Go to "https://app.windmill.dev/resources?connect_app=gmail" to connect Gmail, 
        then select your token from the dropdown in the arguments window.
        (Click "Refresh" if you don't see your resource in the list.)\n`);
      }
    
      const text = `From: <${user_id}>\nTo: <${to_email}>\nSubject: ${subject}\n\r ${message}`;
      const textEncoder = new TextEncoder();
      const email = base64UrlEncode(textEncoder.encode(text));
      const body = JSON.stringify({
        raw: email,
      });
      const SEND_URL = `https://gmail.googleapis.com/gmail/v1/users/${user_id}/messages/send`;
    
      const response = await fetch(SEND_URL, {
        method: "POST",
        headers: { Authorization: "Bearer " + token },
        body,
      });
    
      const result = await handleSendEmailResult(await response.json(), to_email);
      return result;
    }
    
    async function handleSendEmailResult(result: object, to_email: string) {
      if (Object.keys(result).includes("error")) {
        return Promise.reject({ wm_to_email: to_email, ...result });
      }
    
      return result;
    }
    

    Submitted by admin 1019 days ago

  • deno
    import {
      encode as base64UrlEncode,
    } from "https://deno.land/[email protected]/encoding/base64url.ts";
    
    /**
     * @param user_id User's email address. The special value `me` can be used to indicate the authenticated user.
     */
    type Gmail = {
      token: string;
    };
    export async function main(
      gmail_auth: Gmail,
      to_email: string,
      subject: string,
      message: string,
      user_id: string = "me"
    ) {
      const token = gmail_auth['token']
      if(!token) {
        throw Error(`
        No authentication token was found.
        Go to "https://app.windmill.dev/resources?connect_app=gmail" to connect Gmail, 
        then select your token from the dropdown in the arguments window.
        (Click "Refresh" if you don't see your resource in the list.)\n`)
      }
    
      const text = `From: <${user_id}>\nTo: <${to_email}>\nSubject: ${subject}\n\r ${message}`;
      const textEncoder = new TextEncoder();
      const email = base64UrlEncode(textEncoder.encode(text));
      const body = JSON.stringify({
        raw: email
      });
      const SEND_URL = `https://gmail.googleapis.com/gmail/v1/users/${user_id}/messages/send`;
    
      const response = await fetch(SEND_URL, {
        method: "POST",
        headers: { Authorization: "Bearer " + token },
        body
      });
    
      const result = await handleSendEmailResult(await response.json(), to_email);
      return result;
    }
    
    async function handleSendEmailResult(result: object, to_email: string) {
      if (Object.keys(result).includes('error')) {
        return Promise.reject({ wm_to_email: to_email, ...result });
      }
    
      return result;
    }

    Submitted by admin 1023 days ago

  • deno
    import * as wmill from "https://deno.land/x/[email protected]/mod.ts";
    import {
      encode as base64UrlEncode,
    } from "https://deno.land/[email protected]/encoding/base64url.ts";
    
    /**
     * @param user_id User's email address. The special value `me` can be used to indicate the authenticated user.
     */
    export async function main(
      gmail_auth: wmill.Resource<"gmail">,
      to_email: string,
      subject: string,
      message: string,
      user_id: string = "me"
    ) {
      const token = gmail_auth['token']
      if(!token) {
        throw Error(`
        No authentication token was found.
        Go to "https://app.windmill.dev/resources?connect_app=gmail" to connect Gmail, 
        then select your token from the dropdown in the arguments window.
        (Click "Refresh" if you don't see your resource in the list.)\n`)
      }
    
      const text = `From: <${user_id}>\nTo: <${to_email}>\nSubject: ${subject}\n\r ${message}`;
      const textEncoder = new TextEncoder();
      const email = base64UrlEncode(textEncoder.encode(text));
      const body = JSON.stringify({
        raw: email
      });
      const SEND_URL = `https://gmail.googleapis.com/gmail/v1/users/${user_id}/messages/send`;
    
      const response = await fetch(SEND_URL, {
        method: "POST",
        headers: { Authorization: "Bearer " + token },
        body
      });
    
      const result = await handleSendEmailResult(await response.json(), to_email);
      return result;
    }
    
    async function handleSendEmailResult(result: object, to_email: string) {
      if (Object.keys(result).includes('error')) {
        return Promise.reject({ wm_to_email: to_email, ...result });
      }
    
      return result;
    }

    Submitted by adam186 1151 days ago

  • deno
    import * as wmill from "https://deno.land/x/[email protected]/mod.ts";
    import {
      encode as base64UrlEncode,
    } from "https://deno.land/[email protected]/encoding/base64url.ts";
    
    /**
     * @param user_id User's email address. The special value `me` can be used to indicate the authenticated user.
     */
    export async function main(
      gmail_auth: wmill.Resource<"gmail">,
      to_email: string,
      subject: string,
      message: string,
      user_id: string = "me"
    ) {
      const token = gmail_auth['token']
      if(!token) {
        throw Error(`
        No authentication token was found.
        Go to "https://app.windmill.dev/resources?connect_app=gmail" to connect Gmail, 
        then select your token from the dropdown in the arguments window.
        (Click "Refresh" if you don't see your resource in the list.)\n`)
      }
    
      const text = `From: <${user_id}>\nTo: <${to_email}>\nSubject: ${subject}\n\r ${message}`;
      const textEncoder = new TextEncoder();
      const email = base64UrlEncode(textEncoder.encode(text));
      const body = JSON.stringify({
        raw: email
      });
      const SEND_URL = `https://gmail.googleapis.com/gmail/v1/users/${user_id}/messages/send`;
    
      const response = await fetch(SEND_URL, {
        method: "POST",
        headers: { Authorization: "Bearer " + token },
        body
      });
    
      const result = await handleSendEmailResult(await response.json(), to_email);
      return result;
    }
    
    async function handleSendEmailResult(result: object, to_email: string) {
      if (Object.keys(result).includes('error')) {
        return Promise.reject({ wm_to_email: to_email, ...result });
      }
    
      return result;
    }

    Submitted by adam186 1186 days ago

  • deno
    import * as wmill from "https://deno.land/x/[email protected]/mod.ts";
    import {
      encode as base64UrlEncode,
    } from "https://deno.land/[email protected]/encoding/base64url.ts";
    
    /**
     * @param user_id User's email address. The special value `me` can be used to indicate the authenticated user.
     */
    export async function main(
      gmail_auth: wmill.Resource<"gmail">,
      to_email: string,
      subject: string,
      message: string,
      user_id: string = "me"
    ) {
      const token = gmail_auth['token']
      if(!token) {
        throw Error(`
        No authentication token was found.
        Go to "https://app.windmill.dev/resources?connect_app=gmail" to connect Gmail, 
        then select your token from the dropdown in the arguments window.
        (Click "Refresh" if you don't see your resource in the list.)\n`)
      }
    
      const text = `From: <${user_id}>\nTo: <${to_email}>\nSubject: ${subject}\n\r ${message}`;
      const textEncoder = new TextEncoder();
      const email = base64UrlEncode(textEncoder.encode(text));
      const body = JSON.stringify({
        raw: email
      });
      const SEND_URL = `https://gmail.googleapis.com/gmail/v1/users/${user_id}/messages/send`;
    
      const response = await fetch(SEND_URL, {
        method: "POST",
        headers: { Authorization: "Bearer " + token },
        body
      });
    
      const result = await handleSendEmailResult(await response.json(), to_email);
      return result;
    }
    
    async function handleSendEmailResult(result: object, to_email: string) {
      if (Object.keys(result).includes('error')) {
        return Promise.reject({ wm_to_email: to_email, ...result });
      }
    
      return result;
    }

    Submitted by mrl5 1280 days ago

  • deno
    import * as wmill from "https://deno.land/x/[email protected]/mod.ts";
    import {
      encode as base64UrlEncode,
    } from "https://deno.land/[email protected]/encoding/base64url.ts";
    
    /**
     * @param user_id User's email address. The special value `me` can be used to indicate the authenticated user.
     */
    export async function main(
      gmail_auth: wmill.Resource<"gmail">,
      to_email: string,
      subject: string,
      message: string,
      user_id: string = "me"
    ) {
      const token = gmail_auth['token']
      if(!token) {
        throw Error(`
        No authentication token was found.
        Go to "https://app.windmill.dev/resources?connect_app=gmail" to connect Gmail, 
        then select your token from the dropdown in the arguments window.
        (Click "Refresh" if you don't see your resource in the list.)\n`)
      }
    
      const text = `From: <${user_id}>\nTo: <${to_email}>\nSubject: ${subject}\n\r ${message}`;
      const textEncoder = new TextEncoder();
      const email = base64UrlEncode(textEncoder.encode(text));
      const body = JSON.stringify({
        raw: email
      });
      const SEND_URL = `https://gmail.googleapis.com/gmail/v1/users/${user_id}/messages/send`;
    
      const response = await fetch(SEND_URL, {
        method: "POST",
        headers: { Authorization: "Bearer " + token },
        body
      });
    
      return await response.json();
    }

    Submitted by adam186 1283 days ago