Can I send image over Sengrid mail system on OpenSaaS?

I believe sending images needs serialization, how can I achieve that, what steps should I follow. I can send text as mail but don't know how to send image.
11 Replies
kapa.ai
kapa.ai•7d ago
Hi @skyblade2954. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To answer your question about sending images via SendGrid in OpenSaaS using Wasp, I'll need to provide some context and steps based on the available information: 1. Wasp supports email sending functionality, including through SendGrid as a provider Docs > Advanced > Sending Emails (https://wasp-lang.dev/docs/advanced/email). 2. To use SendGrid, you need to set it up in your main.wasp file and configure the API key in your .env.server file Docs > Advanced > Sending Emails > Providers > Using the SendGrid Provider (https://wasp-lang.dev/docs/advanced/email#using-the-sendgrid-provider). 3. For sending emails with attachments (like images), you would typically use the emailSender.send() method Docs > Advanced > Sending Emails > Sending Emails (https://wasp-lang.dev/docs/advanced/email#sending-emails-1). However, the provided knowledge sources don't contain specific information about sending images or attachments via SendGrid in Wasp or OpenSaaS. The documentation mainly covers sending text and HTML emails. To send images, you would typically need to: 1. Encode the image (usually as base64) 2. Attach it to the email using the appropriate API method But without specific Wasp documentation on this feature, I can't provide you with the exact steps or code to achieve this in OpenSaaS. If you need to implement this feature, you might want to: 1. Check the SendGrid documentation for attaching images to emails 2. Look into how to integrate this with Wasp's email sending functionality 3. Consider asking in the Wasp community forums or GitHub issues for more specific guidance I apologize that I don't have enough information to provide a complete answer to your question about sending images via SendGrid in OpenSaaS using Wasp. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @skyblade2954, 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?
miho
miho•6d ago
Do you mean to emebed an image with <img> tag or send an attachment?
skyblade2954
skyblade2954OP•6d ago
I would like to send image from my OpenSaaS react app. To do that I need to attach image to my mail.
miho
miho•6d ago
Is it the same image every time (like the logo of your app) or is it some image you generated and is different each time? If you put the logo in the public/ dir it will be available at yourapp.com/yourimage.png when you deploy 🙂 If you are really looking to send attachments - Wasp doesn't currently support that with emailSender but you need to create your new SendGrid instance to use it directly for this particular email sending task. It's an open issue for us: https://github.com/wasp-lang/wasp/issues/1553
skyblade2954
skyblade2954OP•6d ago
I would like to upload it from the GUI and send through sendgrid. "you need to create your new SendGrid instance to use it directly for this particular email sending task." Is it doable? I am sending mails with below code: import { emailSender } from 'wasp/server/email'; export const sendGUIMailRequest = async ({ inputName, inputEmail, inputSubject, inputPhone, inputEmailBody }) => { try { const emailText = Name: ${inputName} Email: ${inputEmail} Phone: ${inputPhone} Message: ${inputEmailBody} ; const emailHtml = <p><strong>Name:</strong> ${inputName}</p> <p><strong>Email:</strong> ${inputEmail}</p> <p><strong>Phone:</strong> ${inputPhone}</p> <p><strong>Message:</strong></p> <p>${inputEmailBody}</p> ; console.log (emailHtml); console.log (emailText); const info = await emailSender.send({ from: { name: 'customer', email: '[email protected]', }, to: "[email protected]", subject: inputSubject, text: emailText, html: emailHtml, }); return { success: true, info }; } catch (error) { return { success: false, error }; } }; export default sendGUIMailRequest;
miho
miho•6d ago
Hey just a tip: to send codeblocks you can use three ` to wrap them 🙂 https://www.markdownguide.org/extended-syntax/#fenced-code-blocks This is what Wasp is doing under the hood for you:
import SendGrid from "@sendgrid/mail";

// Next line is maybe not necessary since Wasp already set this - but maybe it is, needs to be tested
// SendGrid.setApiKey(API_KEY);
return SendGrid.send({
from: {
email: fromField.email,
name: fromField.name,
},
to: email.to,
subject: email.subject,
text: email.text,
html: email.html,
});
import SendGrid from "@sendgrid/mail";

// Next line is maybe not necessary since Wasp already set this - but maybe it is, needs to be tested
// SendGrid.setApiKey(API_KEY);
return SendGrid.send({
from: {
email: fromField.email,
name: fromField.name,
},
to: email.to,
subject: email.subject,
text: email.text,
html: email.html,
});
You can try using this directly so you have access to the full SendGrid SDK e.g. sending attachments: https://github.com/sendgrid/sendgrid-nodejs/blob/main/docs/use-cases/attachments.md
GitHub
sendgrid-nodejs/docs/use-cases/attachments.md at main · sendgrid/se...
The Official Twilio SendGrid Led, Community Driven Node.js API Library - sendgrid/sendgrid-nodejs
Extended Syntax | Markdown Guide
Advanced features that build on the basic Markdown syntax.
skyblade2954
skyblade2954OP•6d ago
Hello thank you. It worked. I can now send images. Do you think this has a disadvantage/drawback?
miho
miho•6d ago
There shouldn't be any downsides, we should give a better way to do this in Wasp - e.g. exposing the SendGrid instance so you don't have to think about it - but this is also fine
skyblade2954
skyblade2954OP•6d ago
I faced an issue tho. Size bigger than 1 MB, have issues. Images needs to be smaller than 1 MB or something. Let me see what causes that. @miho Maybe you can help, I need to increase the body size limiti to 50 MB
import express from 'express';

export const serverSetup = async (expressApp) => {
// Increase the request size limit to 50MB
expressApp.use(express.json({ limit: '50mb' }));
expressApp.use(express.urlencoded({ limit: '50mb', extended: true }));
};
import express from 'express';

export const serverSetup = async (expressApp) => {
// Increase the request size limit to 50MB
expressApp.use(express.json({ limit: '50mb' }));
expressApp.use(express.urlencoded({ limit: '50mb', extended: true }));
};
Chatgpt tells me to it with this, but somehow I couldn't add a server configuration. It continue give error. What is ur suggestion?
MEE6
MEE6•6d ago
Wohooo @skyblade2954, you just became a Waspeteer level 8!
martinsos
martinsos•6d ago
There are similar solutions on Discord here, if you search for it I believe you should find solutions for this!
Want results from more Discord servers?
Add your server