Ruby on Rails, is a server-side web app framework. This article helps you set up Heroku app for Ruby on Rails, and how to use Aspose.Email Cloud for email sending.
Ruby on Rails, is a server-side web application framework written in Ruby. Rails is a model view controller framework, providing default structures for a database, a web service, and web pages. Heroku is a platform as a service (PaaS) that enables developers to build, run, and operate applications entirely in the cloud. It supports several programming languages including Ruby on Rails. This blog guides you on how to deploy a Ruby on Rails application to Heroku. The article helps you understand Aspose.Email Cloud, and how to use it for email sending using Heroku Ruby on Rails. The article assumes that you already have a free Heroku Account setup and Ruby and Bundler installed locally. Bundler provides a consistent environment for Ruby projects by tracking and installing the exact gems and versions that are needed. Let’s get started!
- Setup Heroku
- Setup Aspose.Email Cloud
- Email Sending using Aspose.Email Cloud
- Deploy to Heroku
To get started you first need to install the Heroku Command Line Interface (CLI). Heroku CLI is used to manage and perform various scalability tasks. You can use this to provision add-ons, view your application logs, and run your application locally. If you are using macOS, you can use Homebrew to install it or can visit the official Heroku.
brew install heroku/brew/heroku
Once the installation is done you can run the following command to authenticate Heroku to be used locally.
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 email@example.com
This command opens your browser to the Heroku login page for authentication. This is required for both Heroku and git commands to work properly
Setup Aspose.Email Cloud
Aspose.Email Cloud is a Cloud SDK to send, receive, append, flag, and convert cloud emails & support to create a folder structure for email archiving in the cloud. This is easy to use and fast API, that doesn’t need to install the additional software. The API supports many programming languages, such as C#, Java, PHP, Python, Ruby & Typescript. To set up Aspose.Email Cloud follows the instructions as below.
Login to Aspose.Cloud Dashboard and click the Applications tab in the left sidebar. Now scroll down, click Create New Application button as shown in the image below.
Now create your new application by selecting your default storage as shown in the image below. You can also configure third-party storage to upload your data files by following how to configure 3rd party cloud storage guide.
Now, scroll down towards the Client Credentials section to copy Client Id and Client Secret as shown in the image below.
Email Sending using Aspose.Email Cloud
Assuming you’ve already installed Ruby 2.7 and Bundler. You now have a functioning git repository that contains a simple application as well as Gemfile file which is used by Ruby’s dependency manager, bundler.
$ mkdir my-email-sending-app $ cd my-email-sending-app $ gem install aspose_email_cloud
add the following code in your ruby project
require 'aspose-email-cloud' include AsposeEmailCloud // Setup App Credentials @api = EmailCloud.new('client_secret', 'client_id') credentials = EmailClientAccountPasswordCredentials.new( login: 'firstname.lastname@example.org', password: 'password') // Setup an email account for email sending send_account_dto = EmailClientAccount.new( host: 'smtp.gmail.com', port: 465, security_options: 'SSLAuto', protocol_type: 'SMTP', credentials: credentials) smtp_account = 'smtp.account' smtp_location = StorageFileLocation.new( storage: storage_name, folder_path: account_folder, file_name: smtp_account) # Save account api.client.account.save(ClientAccountSaveRequest.new( storage_file: smtp_location, value: send_account_dto)) email = EmailDto.new( from: MailAddress.new(address: 'email@example.com'), to: [MailAddress.new(address: 'firstname.lastname@example.org')], subject: 'Some subject', body: 'Some body' ) api.client.message.send( ClientMessageSendRequest.new( account_location: smtp_location, message: MailMessageDto.new(value: email)))
Deploy to Heroku (Ruby on Rails)
Once you are done with all your changes and ready to deploy to Heroku (Ruby on Rails), you can use the following commands to push your changes to Heroku.
$ heroku create Creating sharp-rain-221... done, stack is heroku-20 http://sharp-rain-221.herokuapp.com/ | https://git.heroku.com/sharp-rain-221.git Git remote heroku added
this will create a git repository on Heroku and anything you push to this repo will deploy to Heroku(Ruby on Rails).
$ git push heroku main
Now you can open your application using the heroku open command.
In this article, we learned about the Heroku platform as a service (PaaS) and how it enables developers to build, run, and operate applications entirely in the cloud. We also learned how to set up a Heroku Ruby on Rails. We also explored the Aspose.Email Cloud, and used to set up an SMTP email client for email sending. Aspose.Email Cloud isn’t just for sending emails. Instead, it’s a Cloud SDK to send, receive, append, flag, and convert cloud emails & support to create a folder structure for email archiving in the cloud. This is easy to use and fast API, that doesn’t need to install the additional software. The API supports many programming languages, such as C#, Java, PHP, Python, Ruby & Typescript. I hope this article helped you.