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
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?Do you mean to emebed an image with
<img>
tag or send an attachment?I would like to send image from my OpenSaaS react app. To do that I need to attach image to my mail.
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/1553I 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;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:
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.
Hello thank you.
It worked.
I can now send images. Do you think this has a disadvantage/drawback?
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 fineI 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
Chatgpt tells me to it with this, but somehow I couldn't add a server configuration. It continue give error. What is ur suggestion?
Wohooo @skyblade2954, you just became a Waspeteer level 8!
There are similar solutions on Discord here, if you search for it I believe you should find solutions for this!