Heroku Node.js 앱에서 Aspose.Email Cloud를 사용하여 이메일 보내기

heroku node.js 앱을 설정하는 방법과 Node.js 애플리케이션에서 이메일을 보내기 위해 Aspose.Email Cloud를 사용하는 방법에 대한 자습서입니다.

이 블로그는 Heroku에 Node.js 앱을 배포하는 방법을 안내합니다. 또한 이 기사는 Aspose.Email Cloud를 이해하고 이를 이메일 전송에 사용하는 방법을 이해하는 데 도움이 됩니다. 이 기사에서는 이미 무료 Heroku 계정 설정과 Node.js 및 NPM이 로컬에 설치되어 있다고 가정합니다. 시작하자!

Heroku 설정

시작하려면 먼저 Heroku 명령줄 인터페이스(CLI)를 설치해야 합니다. Heroku CLI는 다양한 확장성 작업을 관리하고 수행하는 데 사용됩니다. 이를 사용하여 추가 기능을 프로비저닝하고, 애플리케이션 로그를 보고, 애플리케이션을 로컬에서 실행할 수 있습니다. macOS를 사용하는 경우 Homebrew를 사용하여 설치하거나 공식 Heroku를 방문할 수 있습니다.

brew install heroku/brew/heroku

설치가 완료되면 다음 명령을 실행하여 로컬에서 사용할 Heroku를 인증할 수 있습니다.

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

이 명령은 인증을 위해 브라우저에서 Heroku 로그인 페이지를 엽니다. 이것은 Heroku 및 git 명령이 제대로 작동하는 데 필요합니다.

Aspose.Email 클라우드 설정

Aspose.Email Cloud는 클라우드 이메일을 보내고, 받고, 추가하고, 플래그를 지정하고, 변환하고 클라우드에서 이메일 보관을 위한 폴더 구조를 생성하기 위한 지원을 위한 Cloud SDK입니다. 추가 소프트웨어를 설치할 필요가 없는 사용하기 쉽고 빠른 API입니다. API는 C#, Java, PHP, Python, Ruby 및 Typescript와 같은 많은 프로그래밍 언어를 지원합니다. SDK 설치 방법을 알아보려면 공식 가이드의 지침을 따르세요.

Aspose.Email Cloud를 이용한 이메일 전송

Node.js를 이미 설치했다고 가정하고 애플리케이션용 디렉토리를 만드십시오.

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

이제 main.js 파일에 다음 코드를 추가하십시오.

$ 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

//  SDK 가져오기
const email = require('@asposecloud/aspose-email-cloud');
const express = require('express')
const app = express()
const port = 5000

// 앱 자격 증명 설정 
const AsposeApp = {
    ClientId: '\*\*\*\*\*',
    ClientSecret: '\*\*\*\*\*',
}

// 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);

// 이메일 전송을 위한 이메일 계정 설정
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) => {
    // 이메일 계정을 사용하여 이메일 보내기
    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}\`)
})

Heroku에 Node.js 앱 배포

모든 변경을 완료하고 앱을 게시할 준비가 되면 다음 명령을 사용하여 변경 사항을 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

이렇게 하면 Heroku에 git 리포지토리가 생성되고 이 리포지토리에 푸시하는 모든 항목이 Heroku 애플리케이션에 배포됩니다.

$ git push heroku main

이제 heroku open 명령을 사용하여 애플리케이션을 열 수 있습니다.

결론

이 기사에서는 Heroku 플랫폼과 Heroku에서 Node.js 애플리케이션을 사용하여 이메일을 보내는 방법에 대해 배웠습니다. 또한 Aspose.Email Cloud를 살펴보고 온라인으로 이메일을 보내도록 SMTP 이메일 클라이언트를 설정하는 데 사용했습니다. Aspose.Email Cloud는 이메일 전송만을 위한 것이 아닙니다. 대신 클라우드 이메일을 보내고, 받고, 추가하고, 플래그를 지정하고, 변환하고 클라우드에서 이메일 보관을 위한 폴더 구조를 만드는 지원을 하는 것은 Cloud SDK입니다. 추가 소프트웨어를 설치할 필요가 없는 사용하기 쉽고 빠른 API입니다. API는 C#, Java, PHP, Python, Ruby 및 Typescript와 같은 많은 프로그래밍 언어를 지원합니다. 이 기사가 도움이 되었기를 바랍니다.

제품 설명서를 통해 Aspose.Email for Cloud의 기능을 살펴보는 것이 좋습니다. 또한 API 사용 중 문제가 발생하면 무료 제품 지원 포럼을 통해 언제든지 문의하십시오.

탐구하다