Ngirim Email nggunakake Aspose.Email Cloud ing Heroku Node.js App

Tutorial babagan carane nyiyapake aplikasi heroku node.js, lan carane nggunakake Aspose.Email Cloud kanggo ngirim email ing aplikasi Node.js.

Blog iki nuntun sampeyan babagan carane masang aplikasi Node.js ing Heroku. Lan, artikel kasebut mbantu sampeyan ngerti Aspose.Email Cloud, lan cara nggunakake kanggo ngirim email. Artikel kasebut nganggep yen sampeyan wis duwe persiyapan Akun Heroku gratis lan Node.js lan NPM diinstal sacara lokal. Ayo dadi miwiti!

Setup Heroku

Kanggo miwiti sampeyan kudu nginstal Heroku Command Line Interface (CLI). Heroku CLI digunakake kanggo ngatur lan nindakake macem-macem tugas skalabilitas. Sampeyan bisa nggunakake iki kanggo nyedhiyakake tambahan, ndeleng log aplikasi, lan mbukak aplikasi sampeyan sacara lokal. Yen sampeyan nggunakake macOS, sampeyan bisa nggunakake Homebrew kanggo nginstal utawa bisa ngunjungi Heroku resmi.

brew install heroku/brew/heroku

Sawise instalasi rampung sampeyan bisa mbukak printah ing ngisor iki kanggo keasliane Heroku kanggo digunakake sacara lokal.

heroku login
heroku: Press any key to open up the browser to login or q to exit
 ›   Warning: If browser does not open, visit
 ›   https://cli-auth.heroku.com/auth/browser/\*\*\*
heroku: Waiting for login...
Logging in... done
Logged in as me@example.com

Printah iki mbukak browser sampeyan menyang kaca mlebu Heroku kanggo otentikasi. Iki dibutuhake supaya perintah Heroku lan git bisa digunakake kanthi bener

Setup Aspose.Email Cloud

Aspose.Email Cloud minangka Cloud SDK kanggo ngirim, nampa, nambah, menehi tandha, lan ngowahi email & dhukungan maya kanggo nggawe struktur folder kanggo pengarsipan email ing awan. Iki gampang digunakake lan API cepet, sing ora perlu nginstal piranti lunak tambahan. API ndhukung akeh basa pamrograman, kayata C#, Java, PHP, Python, Ruby & Typescript. Kanggo ngerti carane nginstal SDK, tututi pandhuan ing pandhuan resmi.

Ngirim Email nggunakake Aspose.Email Cloud

Yen sampeyan wis nginstal Node.js, mangga gawe direktori kanggo aplikasi sampeyan.

$ mkdir my-email-sending-app
$ cd my-email-sending-app
$ npm init
$ npm install express --save
$ npm install @asposecloud/aspose-email-cloud

Saiki tambahake kode ing ngisor iki ing file main.js sampeyan

$ mkdir my-email-sending-app
$ cd my-email-sending-app
$ npm init
$ npm install express --save
$ npm install @asposecloud/aspose-email-cloud

add following code in your main.js file

//  Ngimpor SDK
const email = require('@asposecloud/aspose-email-cloud');
const express = require('express')
const app = express()
const port = 5000

// Konfigurasi Kredensial Aplikasi 
const AsposeApp = {
    ClientId: '\*\*\*\*\*',
    ClientSecret: '\*\*\*\*\*',
}

// Setel SDK
const api = new email.EmailCloud(AsposeApp.ClientId, AsposeApp.ClientSecret)

const credentials = new email.EmailClientAccountPasswordCredentials(
    'my@email.com', '\*\*\*\*\*');
const receiveAccountDto = new email.EmailClientAccount(
    'smtp.email.com', 465, 'SSLAuto', 'SMTP', credentials);

// Nggawe akun email kanggo ngirim email
const smtpAccount = 'smtp.account';
const storageName = 'MyEmailStorage';
const accountFolder = 'MyEmailFolder';
const smtpLocation = new email.StorageFileLocation(
    storageName, accountFolder, smtpAccount);


app.get('/', async (req, res) => {
  res.send('Welcome to my email sending app in Node.js')
})

app.get('/setup-account', async (req, res) => {
    await api.client.account.save(new email.ClientAccountSaveRequest(smtpLocation, receiveAccountDto));
    res.send('Account setup successfully');
})

app.get('/send-email', async (req, res) => {
    // Kirim email nggunakake akun email
    const emaildto = new email.EmailDto();
    emaildto.from = new email.MailAddress('From address', 'example@gmail.com');
    emaildto.to = [new email.MailAddress('To address', 'to@aspose.com')];
    emaildto.subject = 'Some subject';
    emaildto.body = 'Some body';
    await api.client.message.send(
        new email.ClientMessageSendRequest(
            smtpLocation, new MailMessageDto(emaildto)));
    
    res.send('Email Sent Successfully');

});

app.listen(port, () => {
  console.log(\`Example app listening on port ${port}\`)
})

Pasang Aplikasi Node.js menyang Heroku

Sawise sampeyan wis rampung kabeh owah-owahan lan siap kanggo nerbitaké app, sampeyan bisa nggunakake printah ing ngisor iki kanggo push owah-owahan menyang Heroku.

$ heroku create
Creating sharp-rain-871... done, stack is heroku-18
http://sharp-rain-871.herokuapp.com/ | https://git.heroku.com/sharp-rain-871.git
Git remote heroku added

iki bakal nggawe repositori git ing Heroku lan apa wae sing sampeyan push menyang repo iki bakal disebarake menyang aplikasi Heroku sampeyan.

$ git push heroku main

Saiki sampeyan bisa mbukak aplikasi nggunakake printah mbukak heroku.

Kesimpulan

Ing artikel iki, kita sinau babagan platform Heroku lan ngirim email nggunakake aplikasi Node.js ing Heroku. Kita uga njelajah Aspose.Email Cloud, lan digunakake kanggo nyiyapake klien email SMTP kanggo ngirim email online. Aspose.Email Cloud ora mung kanggo ngirim email. Nanging, iku Cloud SDK kanggo ngirim, nampa, nambah, menehi gendera, lan ngowahi email & dhukungan maya kanggo nggawe struktur folder kanggo pengarsipan email ing awan. Iki gampang digunakake lan API cepet, sing ora perlu nginstal piranti lunak tambahan. API ndhukung akeh basa pamrograman, kayata C#, Java, PHP, Python, Ruby & Typescript. Muga-muga artikel iki mbantu sampeyan.

Disaranake banget kanggo njelajah kemampuan Aspose.Email kanggo Cloud liwat Dokumentasi Produk. Salajengipun, yen sampeyan nemoni masalah nalika nggunakake API, hubungi liwat Forum dhukungan produk gratis.

Jelajahi