SendGrid 403 Error

I have updated this part in main.wasp
emailSender: {
// NOTE: "Dummy" provider is just for local development purposes.
// Make sure to check the server logs for the email confirmation url (it will not be sent to an address)!
// Once you are ready for production, switch to e.g. "SendGrid" or "Mailgun" providers. Check out https://docs.opensaas.sh/guides/email-sending/ .
provider: SendGrid,
defaultFrom: {}
emailSender: {
// NOTE: "Dummy" provider is just for local development purposes.
// Make sure to check the server logs for the email confirmation url (it will not be sent to an address)!
// Once you are ready for production, switch to e.g. "SendGrid" or "Mailgun" providers. Check out https://docs.opensaas.sh/guides/email-sending/ .
provider: SendGrid,
defaultFrom: {}
I didnt do anything else, I have a custom endpoint that sends emails properly, but when I try to register a user via email I get 403
[ Server!] Failed to send email ResponseError: Forbidden
[ Server!] at /home/kaloyan/projects/podcast-FE/app/node_modules/@sendgrid/client/src/classes/client.js:146:29
[ Server!] at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
[ Server!] code: 403,
[ Server!] response: {
[ Server!] headers: {
[ Server!] server: 'nginx',
[ Server!] date: 'Mon, 02 Sep 2024 10:41:16 GMT',
[ Server!] 'content-type': 'application/json',
[ Server!] 'content-length': '281',
[ Server!] connection: 'keep-alive',
[ Server!] 'access-control-allow-origin': 'https://sendgrid.api-docs.io',
[ Server!] 'access-control-allow-methods': 'POST',
[ Server!] 'access-control-allow-headers': 'Authorization, Content-Type, On-behalf-of, x-sg-elas-acl',
[ Server!] 'access-control-max-age': '600',
[ Server!] 'x-no-cors-reason': 'https://sendgrid.com/docs/Classroom/Basics/API/cors.html',
[ Server!] 'strict-transport-security': 'max-age=600; includeSubDomains'
[ Server!] },
[ Server!] body: { errors: [Array] }
[ Server!] }
[ Server!] }
[ Server!] Failed to send email ResponseError: Forbidden
[ Server!] at /home/kaloyan/projects/podcast-FE/app/node_modules/@sendgrid/client/src/classes/client.js:146:29
[ Server!] at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
[ Server!] code: 403,
[ Server!] response: {
[ Server!] headers: {
[ Server!] server: 'nginx',
[ Server!] date: 'Mon, 02 Sep 2024 10:41:16 GMT',
[ Server!] 'content-type': 'application/json',
[ Server!] 'content-length': '281',
[ Server!] connection: 'keep-alive',
[ Server!] 'access-control-allow-origin': 'https://sendgrid.api-docs.io',
[ Server!] 'access-control-allow-methods': 'POST',
[ Server!] 'access-control-allow-headers': 'Authorization, Content-Type, On-behalf-of, x-sg-elas-acl',
[ Server!] 'access-control-max-age': '600',
[ Server!] 'x-no-cors-reason': 'https://sendgrid.com/docs/Classroom/Basics/API/cors.html',
[ Server!] 'strict-transport-security': 'max-age=600; includeSubDomains'
[ Server!] },
[ Server!] body: { errors: [Array] }
[ Server!] }
[ Server!] }
15 Replies
kapa.ai
kapa.ai3w ago
Hi @fustuk.. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- The 403 Forbidden error you're encountering when trying to send emails with SendGrid usually indicates an issue with your API key or its permissions. In your main.wasp file, you've set the email provider to SendGrid, but you also need to add your SendGrid API key to your .env.server file. Here's how you can do it: 1. Go to SendGrid (https://sendgrid.com/) and create an account. 2. Go to API Keys (https://app.sendgrid.com/settings/api_keys) and create a new API key. 3. Copy the API key and add it to your .env.server file like this:
SENDGRID_API_KEY=your_sendgrid_api_key
SENDGRID_API_KEY=your_sendgrid_api_key
Replace your_sendgrid_api_key with the actual API key you got from SendGrid. If you've already done this and you're still getting a 403 error, it's possible that your API key doesn't have the necessary permissions, or it's incorrect. You might want to check it again in your SendGrid account. Also, please note that SendGrid might not accept API calls from a localhost or development environment, as mentioned by a community member in a Discord support thread (https://discord.com/channels/686873244791210014/1215756032064880711). You might want to check if this is the case for you. For more information, you can refer to the Wasp documentation on using the SendGrid provider (https://wasp-lang.dev/docs/advanced/email#using-the-sendgrid-provider). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @fustuk., I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
fustuk.
fustuk.3w ago
yes I have the api keys in the env file @kapa.ai
kapa.ai
kapa.ai3w ago
Let me check the knowledge base for you. One moment! :books: ---------------------- If you have already added the SendGrid API key to your .env.server file and you're still encountering a 403 Forbidden error, it could be due to a few reasons: 1. Incorrect API Key: Double-check your SendGrid API key to ensure it's correct. Make sure there are no extra spaces or characters. 2. API Key Permissions: Your SendGrid API key might not have the necessary permissions. You can check this in your SendGrid account. 3. Localhost Restrictions: As mentioned in a Discord support thread (https://discord.com/channels/686873244791210014/1215756032064880711), SendGrid might not accept API calls from a localhost or development environment. If you're running your application locally, this could be the issue. 4. SendGrid Account Settings: There might be some settings or restrictions in your SendGrid account that are preventing the API calls. It's worth checking your account settings and any security features that might be blocking the requests. If none of these seem to be the issue, you might want to reach out to SendGrid support for further assistance. They can provide more specific guidance based on your account and API key. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @fustuk., I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
fustuk.
fustuk.3w ago
Api key and permissions shouldnt be the issue here since I already confirmed sendgrid api is working from a custom api endpoint any other suggestions @kapa.ai ?
kapa.ai
kapa.ai3w ago
Let me check the knowledge base for you. One moment! :books: ---------------------- If you've checked all the points mentioned earlier and you're still encountering the issue, here are a few more suggestions: 1. Check the Error Details: The error message should include more details in the errors array. This might give you more information about what's causing the issue. 2. Check Your SendGrid Account Status: Ensure your SendGrid account is active and not suspended or under review. Sometimes, new accounts or accounts with unusual activity can be temporarily disabled. 3. Test Your API Key with SendGrid's API: You can try making a direct API call to SendGrid using a tool like Postman or curl. This can help you determine if the issue is with your API key or with the way your application is using it. 4. Check for Updates or Issues with Wasp: Ensure you're using the latest version of Wasp. Also, check the Wasp GitHub issues (https://github.com/wasp-lang/wasp/issues) to see if anyone else has reported a similar problem. 5. Reach Out to the Wasp Community: If you're still stuck, consider reaching out to the Wasp community on Discord (https://discord.com/invite/rzdnErX). Other users or the Wasp team might be able to provide further assistance. Remember, when dealing with issues like this, it's important to not share your API keys or other sensitive information publicly. Always keep your keys and other credentials private. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @fustuk., I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
fustuk.
fustuk.3w ago
@martinsos do you have any clues for me on how to debug this 😄
miho
miho3w ago
The code was 403 apparently, which means Forbidden and something is not allowed. Is the e-mail/domain from which you are sending verified? You are 100% sure the things are set up the same in the custom API endpint and in Wasp?
fustuk.
fustuk.3w ago
The custom api works, what doesnt work is the automated verify email that gets sent after email signup
miho
miho3w ago
That doesn't answer my two questions 😄
fustuk.
fustuk.3w ago
I am not sure if Ive done everything in wasp, that is the core of my question :D, I only added emailSender {provider,defaultFrom} and .env.server var thats it for context, this works:
const info = await emailSender.send({
from: {
name: "asd",
email: "example-email",
},
to: context.user.email,
subject: "Video Processed",
text: "Your Video is ready",
html: " <div>\n" +
" <h1 >Your Video is <strong>ready!</strong></h1>\n" +
" </div>",
});
const info = await emailSender.send({
from: {
name: "asd",
email: "example-email",
},
to: context.user.email,
subject: "Video Processed",
text: "Your Video is ready",
html: " <div>\n" +
" <h1 >Your Video is <strong>ready!</strong></h1>\n" +
" </div>",
});
miho
miho3w ago
Please check the defaultFrom under emailSender and fromField under the email auth method. These could have difference from emails and that could be tripping up SendGrid 😄 at least that happened to me one time
fustuk.
fustuk.3w ago
omg okay I missed the fromField... thanks alot again
miho
miho3w ago
No worries, we should make it easier to spot these kind of errors 🤦‍♂️ output something in the console! thanks for your patience
martinsos
martinsos3w ago
We should! @miho shoudl we open an issue for this?
miho
miho3w ago
GitHub
Improve error reporting for email sender · Issue #2266 · wasp-lang/...
Looking at the stack trace in this Discord thread it's obvious we are not outputting the full error which is crucial for successful debugging. Also, we could maybe recognise common sets of erro...
Want results from more Discord servers?
Add your server