muratgozel / MIMEText

RFC-2822, RFC-2045 and RFC-2049 compliant raw email message generator.
https://muratgozel.github.io/MIMEText/
MIT License
80 stars 35 forks source link

Type MimeMessage is incorrect in "@types/mimetext": "^2.0.3" for "mimetext": "^3.0.16" and is also misleading compared to the docs #54

Closed DavidSchmidtPocket closed 7 months ago

DavidSchmidtPocket commented 11 months ago

const message = createMimeMessage(); message.setSender('fake@email.com'); message.setTo('fake2@email.com'); message.setSubject('Test Email Please Ignore'); //message.setMessage('text/plain', 'yo'); // setMessage is not a function //@ts-expect-error // addMessage works just fine, but typescript doesn't know about it message.addMessage({ contentType: 'text/plain', data: 'Yo', }); const res = await gmailFetch( 'https://gmail.googleapis.com/gmail/v1/users/me/messages/send', { method: 'POST', body: JSON.stringify({ raw: message.asEncoded() }) }, );

TLDR: the docs suggest using addMessage, but it's not a valid type. setMessage is a valid type, but doesn't actually exist on the message object. There may be other mismatches, but this is the only one I've run into thus far.

einarpersson commented 9 months ago

Just ran into this as well! 🤯

@DavidSchmidtPocket What did you do to work around this?

@muratgozel Please look into this as it is quite a severe problem imo (that the type definitions / docs are simply wrong)

rickmeier1 commented 8 months ago

This is a big deal. Not a usable product for typescript.

DavidSchmidtPocket commented 7 months ago

Just ran into this as well! 🤯

@DavidSchmidtPocket What did you do to work around this?

@muratgozel Please look into this as it is quite a severe problem imo (that the type definitions / docs are simply wrong)

Sorry, I missed these responses. Found the correct (hidden) api and tsignored it essentially.


  body,
  to,
  subject,
  cc,
  bcc,
  replyToMessageId,
  threadId,
}: {
  body: string;
  subject: string;
  to: string[];
  cc: string[];
  bcc: string[];
  replyToMessageId?: string;
  threadId?: string;
}) => {
  const { userId, currentUserEmail } = await authAndGetCurrentUserEmail();
  if (!userId) {
    return { status: 401, message: 'User not logged in.' };
  } else if (!currentUserEmail) {
    return { status: 401, message: 'User email not found.' };
  }

  const message = createMimeMessage();
  message.setSender(currentUserEmail);
  message.setTo(to);
  message.setCc(cc);
  message.setBcc(bcc);
  message.setSubject(subject);
  if (replyToMessageId) {
    message.setHeader('In-Reply-To', replyToMessageId);
    message.setHeader('References', replyToMessageId);
  }
  //message.setMessage('text/plain', 'yo'); // setMessage is not a function
  //@ts-expect-error // addMessage works just fine, but typescript doesn't know about it
  message.addMessage({
    contentType: 'text/plain',
    data: body,
  });
  const res = await gmailFetch(
    'https://gmail.googleapis.com/gmail/v1/users/me/messages/send',
    {
      method: 'POST',
      body: JSON.stringify({ raw: message.asEncoded(), threadId }),
    },
  );
  revalidatePath('/');
  if (res) {
    return { status: 200, message: 'Email sent successfully.' };
  } else {
    return { status: 500, message: 'Failed to send email.' };
  }
};```
muratgozel commented 7 months ago

hey, mimetext has type definitions inside the package, you dont need to use @types/mimetext. i should probably make a request for removal from there.