Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble with SendGrid Provider: Sender From Name #118

Open
thongbn opened this issue Jan 5, 2023 · 4 comments
Open

Trouble with SendGrid Provider: Sender From Name #118

thongbn opened this issue Jan 5, 2023 · 4 comments

Comments

@thongbn
Copy link

thongbn commented Jan 5, 2023

Bug report

Describe the bug

From name for Strapi Sendgrid email provider.

Steps to reproduce the behavior

Change "from" in SendOptions from string to object for Sender Name in SendGrid Api will cause Error

strapi
      .plugin('email-designer')
      .service('email')
      .sendTemplatedEmail({
        to: sendTo,
        from: {
          email: process.env.DEFAULT_FROM_EMAIL,
          name: process.env.DEFAULT_FROM_EMAIL_NAME
        }
      }, {
        templateReferenceId: templateReferenceId
      }, {
        ...result,
        registeredDate: moment(result.createdAt).format("DD-MM-YYYY")
      })
      .catch(e => {
        console.error("Send email fail", e);
        strapi.log.error("Send mail error", e);
      });

It will got error in node_modules/strapi-plugin-email-designer/server/services/email.js

if (!isValidEmail.test(email)) throw new Error(`Invalid "${key}" email address with value "${email}"`);

I have to modify it to work with SendGrid email provider

let testAdress = address.email ? address.email : address;
if (!isValidEmail.test(testAdress)) throw new Error(`Invalid "${key}" email address with value "${address}"`);

Does have any another way to do it but not modify library code

System

  • Node.js version: v16
  • NPM version:
  • Strapi version: 4.5.5
  • Plugin version:
  • Database: mariadb
  • Operating system:
@github-actions
Copy link

github-actions bot commented Jan 5, 2023

Thank you!! This is your first issue on this repo

@creazy231
Copy link
Collaborator

creazy231 commented Aug 16, 2023

Could you please try the following code:

strapi
      .plugin('email-designer')
      .service('email')
      .sendTemplatedEmail({
        to: sendTo,
+       from: `${process.env.DEFAULT_FROM_EMAIL_NAME} <${process.env.DEFAULT_FROM_EMAIL}>`,
-       from: {
-         email: process.env.DEFAULT_FROM_EMAIL,
-         name: process.env.DEFAULT_FROM_EMAIL_NAME
-       }
      }, {
        templateReferenceId: templateReferenceId
      }, {
        ...result,
        registeredDate: moment(result.createdAt).format("DD-MM-YYYY")
      })
      .catch(e => {
        console.error("Send email fail", e);
        strapi.log.error("Send mail error", e);
      });

This change should get the result you want without the need to change anything on package side

@thongbn
Copy link
Author

thongbn commented Aug 17, 2023

@creazy231 thank you so much

@creazy231
Copy link
Collaborator

You're welcome 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants