Back

Can't add CC to send email function

  • 0
  • Functions
  • Web
yehior
14 Sep, 2024, 08:06

Hi, I was trying to create an email notification function, the code below works perfectly for single recipient, but I can't added more recipients using cc/bcc.

I have tried so many syntax but can't find the correct one, anyone know how to solve this so I can add more emails using CC? I have tried both email and UID btw

TypeScript
  recipientEmail: string,
  subject: string,
  content: string,
  appointmentSchedule: Date
) => {
  try {
    const scheduledTime = new Date(appointmentSchedule).toISOString();

    console.log(ID.unique());
    // console.log(ccEmails);
    console.log(recipientEmail);

    const message = await messaging.createEmail(
      ID.unique(), // Unique message ID
      subject, // Subject of the email
      content, // Content of the email
      [], // Topics (optional)
      [recipientEmail], // List of user emails (you can include more)
      [], // Targets (optional)
      ["example@mail.com"], // CC (optional)
      [], // BCC (optional)
      [], // Attachments (optional)
      false, // Draft (optional)
      true, // HTML content
      scheduledTime
    );

    return parseStringify(message);
  } catch (error) {
    console.error("An error occurred while sending email:", error);
  }
};```
TL;DR
Developers are trying to add CC to their email function but encountering issues with incorrect syntax. Errors received indicate invalid parameters for CC and BCC. The function works for single recipients but not multiple. To fix this, ensure the array for CC/BCC contains valid emails or UIDs.
yehior
14 Sep, 2024, 08:08

Here are the errors I encounter:

TypeScript
  type: 'general_argument_invalid',
  response: {
    message: "Invalid `bcc` param: Value must a valid array and UID must contain at most 36 chars. Valid chars are a-z, A-Z, 0-9, and underscore. Can't start with a leading underscore",
    code: 400,
    type: 'general_argument_invalid',
    version: '1.6.0'
  }```

```code: 400,
  type: 'message_target_not_email',
  response: {
    message: 'Message with the target ID is not an email target.',
    code: 400,
    type: 'message_target_not_email',
    version: '1.6.0'
  }```
Joshi
14 Sep, 2024, 08:30

You are supposed to use the target ID

yehior
14 Sep, 2024, 08:41

Oh, may I know where I can get the ID sir?

yehior
14 Sep, 2024, 08:44

Is it these IDs?

yehior
14 Sep, 2024, 08:50

hmm it's not working

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more