Sendgrid-nodejs: Response to preflight request doesn't pass access control check

Created on 21 Aug 2018  路  2Comments  路  Source: sendgrid/sendgrid-nodejs

Issue Summary

I am trying to set up sendgrid mail so I can get a successful demo of my site set up where I need to auto email people. Please let me know if I am being silly as I am still learning and haven't been able to find much on this issue

Steps to Reproduce

  1. follow https://github.com/sendgrid/sendgrid-nodejs/tree/master/packages/mail quickstart
  2. make a button to activate trigger the email sending
  3. Get the error Failed to load https://api.sendgrid.com/v3/mail/send: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header has a value 'https://sendgrid.api-docs.io' that is not equal to the supplied origin. Origin 'http://localhost:3001' is therefore not allowed access. Have the server send the header with a valid value, or, if an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

As stated above I may be missing something completely obvious. I expect it to be sending an email to myself for testing purposes

code follows

Email.js

     // import sgMail from '@sendgrid/mail'
    class Email {
     static sender(recipiant){
     // using SendGrid's v3 Node.js Library
     // https://github.com/sendgrid/sendgrid-nodejs
     const sgMail = require('@sendgrid/mail');
     sgMail.setApiKey(process.env.SENDGRID_API_KEY);
     const msg = {
      to: recipiant,
      from: '[email protected]',
      subject: 'Sending with SendGrid is Fun',
      text: 'and easy to do anywhere, even with Node.js',
      html: 'and easy to do anywhere, even with Node.js',
      };
      sgMail.send(msg);
      }
     }
    module.exports = Email

index.js

    import Email from '../sendgrid/email.js'
      handleClick (event) {
           Email.sender('[email protected]'); 
       }
        <button onClick={this.handleClick}>
    send email
    </button>
unknown or a waiting for feedback question

All 2 comments

Hello @BestLuke,

We do not support sending emails from the front end of your application and here is the reasoning.

We suggest you trigger the email from the front end, but call a service on the backend that actually sends the email.

With Best Regards,

Elmer

Too bad. How about SPA and webassembly applications? How about progressive web apps, electron apps...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Chrischuck picture Chrischuck  路  3Comments

nicoasp picture nicoasp  路  3Comments

murphman300 picture murphman300  路  4Comments

kiranshashiny picture kiranshashiny  路  4Comments

agostonbonomi picture agostonbonomi  路  3Comments