Edits history of script submission #394 for ' Send an email using mailgun (mailgun)'

  • deno
    import * as wmill from "https://deno.land/x/[email protected]/mod.ts";
    import formData from "npm:[email protected]";
    import Mailgun from "npm:[email protected]";
    
    // fill the type, or use the +Resource type to get a type-safe reference to a resource
    // type Postgresql = object
    
    export async function main(
      mailgunConfig: wmill.Resource<"mailgun">,
      domain: string,
      from: string,
      to: string[],
      subject: string,
      html: string,
    ) {
      const mailgun = new Mailgun(formData);
      const mg = mailgun.client({ username: "api", key: mailgunConfig.api_key });
    
      try {
        const result = await mg.messages.create(domain, {
          from,
          to,
          subject,
          html,
        });
    
        return result;
      } catch (error) {
        console.error(error);
        throw error;
      }
    }
    

    Submitted by aurélien brabant550 1061 days ago