Add custom text to email body automatically when user clicks Reply button

378 Views Asked by At

I am parsing incoming emails to my domain using Mailslurp API and I want to get only the email body without the email signature. I struggled a lot finding out how to recognize signature from the email body but I could not find a satisfying solution till now.

Another alternative I plan to do is add a custom line to the email body like --- reply above this line --- when the receiver of my email clicks on reply button. The user can then add the reply above that line and I can easily extract the content above that line. Do I need to pass that line in the email headers while sending the email? If yes then can anyone please tell me how to pass the same?

Can someone please guide me about how to achieve this? I think this question is a possible duplicate of this question but since that question is unanswered thought of asking this again.

Any help is highly appreciated.

1

There are 1 best solutions below

0
On

Maybe this the examle (at https://www.mailslurp.com/guides/extract-email-content/) helps. Perhaps adjust this for your usage.

it('can extract email content', async () => {
    const mailslurp = new MailSlurp(config);

    const inbox1 = await mailslurp.createInbox();
    const inbox2 = await mailslurp.createInbox();

    const to = [inbox2.emailAddress]
    const body = "Hi there. Your code is: 123456"
    await mailslurp.sendEmail(inbox1.id, { to, body })

    // wait for email
    const email = await mailslurp.waitController.waitForLatestEmail(inbox2.id, timeoutMillis, true)
    const pattern = "code is: ([0-9]{6})"
    expect(email.body).toContain("Your code is")

    const result = await mailslurp.emailController.getEmailContentMatch({ pattern }, email.id)
    expect(result.matches).toHaveLength(2);
    expect(result.matches[0]).toEqual("code is: 123456")
    expect(result.matches[1]).toEqual("123456")
    // now do something with the code
})