Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Play ButtonPause Button
Vuelancer
Vuelancer

Posted on

     

Sending emails in Deno using SMTP module

Hey Developers!

I have created a tutorial for sending emails from your deno project using third party module called smtp.


Introduction

  • You can send email from your deno application.
  • Where we use this thing?
    • Sending verification email to the user after his registration on our project.
    • Sending emails like monthly newsletter, blogs, etc.

Getting Started

import{SmtpClient}from"https://deno.land/x/smtp/mod.ts";import"https://deno.land/x/dotenv/load.ts";
Enter fullscreen modeExit fullscreen mode
  • Creating an instance of SmtpClient
constclient=newSmtpClient();
Enter fullscreen modeExit fullscreen mode
  • Accessing environmental variables
const{SEND_EMAIL,PWD,RECV_EMAIL}=Deno.env.toObject();
Enter fullscreen modeExit fullscreen mode
  • Configuring & Creating the connection
constconnectConfig:any={hostname:"smtp.gmail.com",port:465,username:SEND_EMAIL,password:PWD,};awaitclient.connectTLS(connectConfig);
Enter fullscreen modeExit fullscreen mode
  • Sending the e-mail to the rec. account
awaitclient.send({from:SEND_EMAIL,to:RECV_EMAIL,subject:"Welcome!",content:"Hi from Vuelancer!",});
Enter fullscreen modeExit fullscreen mode
  • Finally, closing the smtp client connection
awaitclient.close();
Enter fullscreen modeExit fullscreen mode

Run the app

$deno run--allow-read--allow-env--allow-net server.ts
Enter fullscreen modeExit fullscreen mode

Or else clone this repo and sculpt it!

~ Thank You!

Support Me

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

150k+ views | Full-stack developer | 6+ years of experience | Youtube content creator
  • Location
    India
  • Education
    Computer Science and Engineering
  • Pronouns
    he
  • Work
    Full-stack developer
  • Joined

More fromVuelancer

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp