Created
May 2, 2026 03:49
-
-
Save iamparthaonline/d8104a5e02ba78373c08a1270b32d0fb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Email } from 'meteor/email'; | |
| import { Meteor } from 'meteor/meteor'; | |
| // Common email layout function | |
| const getCommonEmailLayout = ( | |
| content: string, | |
| lang: 'en' | 'bn' = 'en' | |
| ): string => { | |
| return ` | |
| <!doctype html> | |
| <html lang="${lang}"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| <title>Email</title> | |
| <style> | |
| body { | |
| margin: 0; | |
| padding: 0; | |
| background-color: #f9f9f9; | |
| font-family: Arial, sans-serif; | |
| } | |
| .container { | |
| max-width: 600px; | |
| margin: auto; | |
| background: #fff; | |
| border: 1px solid #ddd; | |
| } | |
| .content { | |
| padding: 20px; | |
| color: #555; | |
| font-size: 16px; | |
| line-height: 22px; | |
| } | |
| .footer { | |
| padding: 20px; | |
| font-size: 14px; | |
| color: #525252; | |
| } | |
| .copyright { | |
| text-align: center; | |
| font-size: 12px; | |
| color: #777; | |
| padding: 20px; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="container"> | |
| <div class="content"> | |
| ${content} | |
| </div> | |
| <div class="footer"> | |
| Best regards,<br><br> | |
| Team [YOUR_APP_NAME]<br> | |
| <a href="[YOUR_WEBSITE_URL]">[YOUR_WEBSITE_URL]</a> | |
| </div> | |
| </div> | |
| <div class="copyright"> | |
| © [YEAR] [YOUR_APP_NAME]. All rights reserved. | |
| </div> | |
| </body> | |
| </html> | |
| `; | |
| }; | |
| // Email utility function (Gmail SMTP / Meteor Email) | |
| export const sendEmail = async ( | |
| to: string, | |
| subject: string, | |
| textContent: string, | |
| htmlContent: string | |
| ): Promise<boolean> => { | |
| try { | |
| const fullHtmlContent = getCommonEmailLayout(htmlContent); | |
| const fromAddress = | |
| Meteor.settings?.private?.MAIL_FROM || | |
| '[YOUR_APP_NAME] <your-email@gmail.com>'; | |
| Email.send({ | |
| to, | |
| from: fromAddress, | |
| subject, | |
| text: textContent, | |
| html: fullHtmlContent, | |
| }); | |
| console.log(`Email sent to ${to}`); | |
| return true; | |
| } catch (error) { | |
| console.error(`Failed to send email to ${to}`, error); | |
| return false; | |
| } | |
| }; | |
| export default sendEmail; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment