0

So I have this:

/**
     * sendNewsletterEmail
     * @param { SibApiV3Sdk.SendSmtpEmailTo[] } to 
     * @param { NewsEmailTemplate } template 
     * @param { TObject } params 
     * @param { SibApiV3Sdk.SendSmtpEmailAttachment[] } attachment 
     * @param { IUsersParsed } bccUsers 
     * @return { Promise<ISibApiV3CreateResponse> }
     */
    public static async sendNewsletterEmail(
        to: SibApiV3Sdk.SendSmtpEmailTo[],
        template: NewsEmailTemplate,
        params: TObject,
        attachment?: SibApiV3Sdk.SendSmtpEmailAttachment[],
        bccUsers?: IUsersParsed[]
    ): Promise<ISibApiV3CreateResponse> {
...}

Problem is whenever I don't pass the attachment parameter and pass the bcc one I get an error because bcc is read as the attachment param. What can I do to solve it?

Im calling it like this (I know its missing the if/else for bcc too)

if (emailAttachments.length) {
            response = await EmailMembership.sendNewsletterEmail(sendTo, template, params, emailAttachments, parsedBcc);
        } else {
            response = await EmailMembership.sendNewsletterEmail(sendTo, template, params, parsedBcc);
        }
Fernanda
  • 59
  • 6
  • 1
    Sounds like you need to pass `undefined` for the attachment. Can you show us how you're calling this? – Nicholas Tower Sep 23 '22 at 12:10
  • like this: if (emailAttachments.length) { response = await EmailMembership.sendNewsletterEmail(sendTo, template, params, emailAttachments, parsedBcc); } else { response = await EmailMembership.sendNewsletterEmail(sendTo, template, params,, parsedBcc); } I know I have to do the if/else for bcc too, but for now is like this – Fernanda Sep 23 '22 at 12:12
  • Yeah, as i guessed, pass in undefined. For example: `EmailMembership.sendNewsletterEmail(sendTo, template, params, undefined, parsedBcc);` – Nicholas Tower Sep 23 '22 at 12:13
  • Doesnt work, the API throws an error – Fernanda Sep 23 '22 at 12:22
  • `Doesnt work, the API throws an error` As far as how to deal with the optional parameter, passing `undefined` is correct. If your code throws an error when it receives an undefined, we'll only be able to help with that if you show us the code and tell us what the error is. – Nicholas Tower Sep 23 '22 at 12:27

0 Answers0