Ku rhumela ti-imeyili i ntirho wa nkoka eka switirhisiwa swo tala, hambi ku ri eka switiviso swa vatirhisi, ku pfuxetiwa ka ntirhisano, kumbe swikongomelo swo xavisa.
Kambe, ku tirhisa swintshuxo swa imeyili minkarhi yin’wana swi nga tika, tanihileswi u faneleke ku hlanganisa poso na ririmi ra xifaniso, kambela ku titshega...
Kambe!
Hi phasela ra @nestixis/nestjs-mailer
, u nga olovisa endlelo leri loko u ri karhi u tiyisisa ku cinca-cinca na ku tshembheka.
Phakeji leyi yi tirhisa matimba ya React na Nodemailer, yi endla leswaku yi va xitirhisiwa xa manguva lawa na lexi nga na xinghana eka vatumbuluxi xo aka tithempleyiti ta imeyili leti cinca-cincaka na ku rhumela ti-imeyili handle ko endla matshalatshala.
A hi ngheneni eka ndlela leyi u nga yi vekaka ha yona ni ku yi tirhisa :)
Ku sungula, u fanele ku nghenisa phasela ra nestjs-mailer
eka xitirhisiwa xa wena xa NestJS. Phasela leri ri kumeka hi ku tirhisa npm, leswi endlaka leswaku ku nghenisa swi hatlisa no olova. Tirhisa xileriso lexi landzelaka eka theminali ya wena:
npm install @nestixis/nestjs-mailer
Loko phasela ri nghenisiwile, goza leri landzelaka i ku lulamisa MailerSdkModule
eka xitirhisiwa xa wena.
Ku lulamisiwa swi kongomile, naswona hi swikongomelo swo kambela, u nga tirhisa xitirhisiwa xo fana na
Hi lexi xikombiso xa ndlela yo yi veka:
import { MailerSdkModule } from '@nestixis/nestjs-mailer'; import { Module } from '@nestjs/common'; import { AppController } from './app.controller'; import { AppService } from './app.service'; @Module({ imports: [ MailerSdkModule.register({ auth: { user: 'username', password: 'password', host: 'sandbox-smtp.mailcatch.app', port: 2525, ssl: false, }, from: '[email protected]', }), ], controllers: [AppController], providers: [AppService], }) export class AppModule {}
Ku endla leswaku ti-imeyili ta wena ti tsakisa hi mahlo naswona ti cinca-cinca, u nga hlanganisa tithempleyiti na React, naswona u phakela @react-email/components
, yi ku pfumelela ku dizayina tithempleyiti to tano ta ti-imeyili.
**Kambe emahlweni ka sweswo, u fanele ku vitana fayili invite-admin-with-account-template.tsx ivi u veka
** ** .
"jsx": "react"
eka tsconfig.json ya wena
Hi lexi xikombiso xa xifaniso xo rhamba mutirhisi lontshwa wa admin:
import { Body, Container, Head, Html, Img, Link, Section, Text, } from '@react-email/components'; import * as React from 'react'; export default function InviteAdminWithAccountTemplate({ translation, language, invitationHref, passwordHref, logoUrl, }) { return ( <Html lang={language}> <Head> <style>{/* Your custom styles here */}</style> </Head> <Body style={{ fontFamily: 'Arial, sans-serif' }}> <Section> <Container> {logoUrl ? ( <Img src={logoUrl} alt="Logo" /> ) : ( <Text>{translation.titleInside}</Text> )} <Text>{translation.contentPart1}</Text> <Text>{translation.contentPart2}</Text> <Text> {translation.contentPart3.subpart1} <Link href={invitationHref}> {translation.contentPart3.subpart2} </Link> {translation.contentPart3.subpart3} </Text> <Text> {translation.contentPart4.subpart1} <Link href={passwordHref}> {translation.contentPart4.subpart2} </Link> </Text> </Container> </Section> </Body> </Html> ); }
Endzhaku ko endla xifaniso xa wena xa imeyili, goza leri landzelaka i ku rhumela imeyili. Ku endla leswi, u nghenisa murhumeri wa imeyili eka vukorhokeri bya wena.
import { EmailSenderInterface, MAILER_SDK_CLIENT, } from '@nestixis/nestjs-mailer'; import { Inject, Injectable } from '@nestjs/common'; import InviteAdminWithAccountTemplate from './invite-admin-with-account-template'; @Injectable() export class AppService { constructor( @Inject(MAILER_SDK_CLIENT) private readonly emailSender: EmailSenderInterface, ) {} async send(): Promise<void> { const translations = { titleInside: { subpart1: 'Welcome', subpart2: ' to the platform!' }, contentPart1: 'Hello', contentPart2: 'Your admin account has been created.', contentPart3: { subpart1: 'Click here to activate your account: ', subpart2: 'Activate', subpart3: '.', }, contentPart4: { subpart1: 'To set your password, click here: ', subpart2: 'Set password', }, }; const emailContent = await InviteAdminWithAccountTemplate({ translation: translations, language: 'en', invitationHref: 'xxx', passwordHref: 'xxx', logoUrl: 'logo.png', }); await this.emailSender.sendEmail( '[email protected]', 'Admin Invitation', emailContent, ); } }
Hi swona! U hlanganisile nestjs-mailer
hi ndlela leyi humelelaka eka xitirhisiwa xa wena.
Ku kuma vuxokoxoko byo tala na swihlawulekisi swa xiyimo xa le henhla, languta eka