Skip to main content


Part-3 NestJS Email With File Attachment

In this article, we are going to implement NestJS sending emails with file attachments. Part-1 NestJS Send Plain Text Email Part-2 NestJS Send Dynamic Generated HTML Template As Email Install @types/nodemailer Package: Let's install the typescript nodemailer package. npm install --save-dev @types/nodemailer Endpoint To Send Email With File Attachment: Let's add a sample image file into the 'mail' folder that we are going to attach to the email. Let's create an endpoint to send the email with a file attachment. src/email.controller.cs: import { join } from 'path'; @Get('file-attachment') async fileAttachement(@Query('toemail') toemail){ var response = await this.mailService.sendMail({ to: toemail, from: '', subject: 'File Attachment', html: "<h1>File Attachment</h1>", attachments:[{ path: join(__dirname,'mails','

Part-2 Generate Dynamic Email Template And Send Email In The NestJS Application

In this article, we are going to generate a dynamic data binding email template and then send emails from the NestJS application. Click here for part-1 Install Handlebar Package: Email body dynamic data binding can be achieved by using the 'Handlebar' libraries. npm install --save handlebars Register Handlebar Configuration: Let's register our handlebar template configuration into the 'MailerModule' in the 'AppModule'. src/app.module.ts: import { MailerModule } from '@nestjs-modules/mailer'; import { Module } from '@nestjs/common'; import { join } from 'path'; import { AppController } from './app.controller'; import { AppService } from './app.service'; import { EmailController } from './email.controller'; import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handlebars.adapter'; @Module({ imports: [ MailerModule.forRoot({ transport: { host: 'smtp.send

Part-1 Email Sending In NestJS Application

In this article, we are going to understand email sending in the NestJS application. SMTP: Simple Mail Transfer Protocol(SMTP) is used to send, and receive emails in any application. So on an email sent, its transferred over the internet from one server to another using SMTP. For our demo, we are going to use the 'SendGrid' a third-party provider SMTP. SendGrid: To establish email communication in our NestJS application using SendGrid, then we need a few configurations from SendGrid like 'SMTP Host', 'from email address' 'user name', and 'password'. Step 1: Go to SendGrid's official website at ''. Next, do signup. Step 2: Now login into the SendGrid website, then under the left-hand side menu go to the 'Settings', then select 'Sender Authentication' menu. At 'Single Sender Verification' click on the 'Get Started' button. Step 3: Let's register the 'From Email Address'

A Demo On .NET6 API Sending Email Using SendGrid NuGet Package

In this article, we are going to implement a sample in .NET6 Web API to send emails using the SendGrid Nuget Package. Create A .Net6 Web API Project: Let's create a .Net6 Web API sample application to accomplish our demo. We can use either Visual Studio 2022 or Visual Studio Code(using .NET CLI commands) to create any.Net6 application. For this demo, I'm using the 'Visual Studio Code'(using the .NET CLI command) editor. CLI command dotnet new webapi -o Your_Project_Name SendGrid: SendGrid is a third-party email provider from which we can deal with 'send', and 'receive' operations of email to our application. SendGrid SMTP(Simple Mail Transfer Protocol) provider for email transfer. SendGrid also provides SendGrid .Net NuGet package that provides easy configuration to any .NET applications. So to use the SendGrid SMTP we need 'Auth Key', 'From Email', so let's register into the SendGrid. The following are the steps to register and

Part-5 A CRUD Operation Demo With .NET6 Web API | SQL Database | Angular13

The main objectives of this article are: Implement HTTP Post Create Action Method In API Implement HTTP Post API Call At Student Service In Angular App Student Component Implement Logic To Create A New Student Implement HTTP Put Update Action Method In API Implement HTTP Put API Call-In Student Service Student Component Implement Logic To Update An Existing Student Implement HTTP Delete Action Method In API Implement HTTP Delete API Call At Student Service Student Component Implement Logic To Delete Student Implement HTTP Post Create Action Method In API: Let's try to create a new student record into our database by implementing the HTTP Post Action Method(or Create action method.) in our 'StudentController'. API_Project/Controllers/StudentController.cs: [HttpPost] public async Task<IActionResult> Post(Student.Api.Data.Entities.Student payload) { _myWorldDbContext.Student.Add(payload); await _myWorldDbContext.SaveChangesAsync(); return Ok(payload); } (Line: 1