EC-Nordbund / denomailer

A SMTP-Client implementation for deno (to send mails!)
https://deno.land/x/denomailer
MIT License
50 stars 16 forks source link

Bug: InReplyTo headers cause havoc #85

Closed samip5 closed 5 months ago

samip5 commented 5 months ago

Describe the bug

It seems that when sendConfig includes InReplyTo, the whole send fails.

To Reproduce

import { SMTPClient as DenoMailerSMTPClient } from "https://deno.land/x/denomailer@1.6.0/mod.ts";

type Smtp = {
  host: string;
  port: number;
};

type EmailObject = {
  from: string;
  cc?: string;
  subject: string;
  content: string;
  inReplyTo?: string; // Added inReplyTo field
  references?: string; // Added references field
};

export async function send_smtp_email(
  smtp_res: Smtp,
  to_email: string,
  from_email: string,
  subject: string,
  content: string,
  cc_email?: string,
  inReplyTo?: string,
  references?: string,
) {
  const client = new DenoMailerSMTPClient({
    debug: {
      allowUnsecure: true,
    },
    connection: {
      hostname: smtp_res.host,
      port: smtp_res.port,
    },
  });

  const headers: { [key: string]: string } = {
    from: from_email,
    to: to_email,
    cc: cc_email || '', // Use the cc_email parameter here
    subject: subject,
    inReplyTo: inReplyTo || '', // Add In-Reply-To header if provided
    references: references || '', // Add References header if provided
  };

  await client.send({
    headers,
    content,
  });

  await client.close();
  return `Email sent from ${from_email} to ${to_email}`;
}

export async function main(email: EmailObject, smtpResource: Smtp) {
  if (email != null) {
    const currentDate = new Date().toLocaleDateString("fi-FI");

    const emailBody = "Hei"
      `On ${currentDate}, ${email.from} wrote:\n` +
      `\"${email.content}\"\n\n`

    const sendEmail = await send_smtp_email(
      smtpResource,
      email.from,
      "sender",
      `Re: ${email.subject}`,
      emailBody,
      "cc",
      email.inReplyTo,
      email.references,
    );

    return sendEmail;
  } else {
    return "NOOP";
  }
}

Expected behavior

I expected it to not cause havoc aka work.

Additional context

TypeError: Cannot use 'in' operator to search for 'mail' in undefined

TypeError: Cannot use 'in' operator to search for 'mail' in undefined
    at parseMailList (https://deno.land/x/denomailer@1.6.0/config/mail/email.ts:55:7)
    at resolveSendConfig (https://deno.land/x/denomailer@1.6.0/config/mail/mod.ts:82:9)
    at SMTPHandler.send (https://deno.land/x/denomailer@1.6.0/client/mod.ts:138:26)
    at send_smtp_email (file:///tmp/windmill/wk-default-zlpd2-habX7/018e5a42-8492-6874-3027-b18bad4b840f/main.ts:46:16)
    at main (file:///tmp/windmill/wk-default-zlpd2-habX7/018e5a42-8492-6874-3027-b18bad4b840f/main.ts:65:29)
    at run (file:///tmp/windmill/wk-default-zlpd2-habX7/018e5a42-8492-6874-3027-b18bad4b840f/wrapper.ts:14:26)
    at file:///tmp/windmill/wk-default-zlpd2-habX7/018e5a42-8492-6874-3027-b18bad4b840f/wrapper.ts:20:11
    at eventLoopTick (ext:core/01_core.js:153:7)

Using Windmil version 1.292.4 instead of Deno directly.