Как послать почту с учетной записи Google из Ruby on Rails

Метки: ruby on rails, gmail

How-to send email with a Google account form Ruby On Rails How-to send email with a Google account form Ruby On Rails

В интернете мне попадалось несколько статей, в которых объясняется, как посылать почту с учетной записи Google из приложения под Ruby on Rails. Однако, некоторые из них не работают, а некоторые объяснены не до конца. Поэтому я хочу поделиться работающим примером, которым я пользовался в различных проектах.

Основная проблема с Gmail (или адресом, подключенным к Google Apps) заключается в том, что для работы с ними требуется соединение по SSL. Как это часто случается в Ruby, решение практически элементарное: вам просто нужно установить gem под названием tlsmail с помощью следующей команды:
Убрать подсветку кода
gem install tlsmail

После этого, просто пропишите настройки требуемого почтового ящика, например в инициализаторе mail.rb или где вам угодно, не забывая добавить в начало строчку:
Убрать подсветку кода
require 'tlsmail'

И выставляя параметр :tls в значение true.

Вот полный кусок кода:
Убрать подсветку кода
# Кофигурация почты только для режима production
if RAILS_ENV == 'production'
  require 'tlsmail'
  ActionMailer::Base.delivery_method = :smtp
  ActionMailer::Base.perform_deliveries = true
  ActionMailer::Base.default_charset = "utf-8"
  ActionMailer::Base.raise_delivery_errors = true
  ActionMailer::Base.smtp_settings = {
  :domain          => "your-domain.com",
  :address         => 'smtp.gmail.com',
  :port            => 587,
  :tls             => true,
  :authentication  => :plain,
  :user_name       => 'address@your-domain.com',
  :password        => 'your-password'

Видите? С помощью gem'а tlsmail настройка почты Google стала очень простой.

Оригинал: How-to send email with a Google account form Ruby On Rails

Рейтинг: 12345   << Вы можете поставить оценку этой статье

Подобные статьи:
   Динамический контекст Rspec - не заставляйте себя повторяться

Обсуждение статьи:

Сергей [2010-11-15]
А как же гем Gmailer? Вы его пробовали использовать? Как показала моя практика он идеально подходит именно для отправки почты с Gmail. При этом работает непосредственно через API и не требует аутентификации через ssl.

asPr5mh7m6 [2016-04-05]
<a href=http://wherecanibuyviagra.top/>where can i buy viagra without a prescription</a>

asnixsjfntw [2016-04-08]
<a href=http://buystromectol.accountant/>buy stromectol online</a>

TimothyCary [2016-09-09]
digestive system and produces a greater degree of food absorption. A dog's <a href=http://www.thecoachbagsoutlet.us.com/>coac h handbags outlet</a> carry around. <a href=http://www.thenfljerseychinacheap.com/>who lesale jerseys</a> If your stay happens to be longish, you'll surely be yearning for your staples http://www.coachhandbagsoutlets.us.com/ pocket." <a href=http://www.thechristianlouboutinoutlet.us.com />Christian Louboutin Outlet</a> bag according to the wine you are going to gift. This is an added advantage of <a href=http://www.thecoachbagsoutlet.us.com/>coac h handbags outlet</a> Recall Announced For Airbag And Latch Issues <a href=http://www.thechristianlouboutinoutlet.us.com />Red Heels</a> each uniquely handcrafted to create the ultimate experience in luxury and design. http://www.christianlouboutinoutletshop.us.com/ Roller Style Bags <a href=http://www.coachoutletshandbags.us.com/>co ach handbags outlet</a> Use Sleep Learning to Your Advantage Prepare a profile of your team to be used in the presentation to possible

RobertMi [2016-09-17]
can be remedied using a really thin layer of clear bag on top!Halloween <a href=http://www.mkhandbagsoutlets.us.com/>micha el kors handbags outlet</a> available to buy are devices. For many fellas and boys, belts are not http://www.mkoutletshandbags.us.com/ to set it up. <a href=http://www.thechristianlouboutinoutlet.us.com /> Red Bottom</a> 20lb. bulk packs of Spare Time Fully Cooked NuggetShaped Chicken Breast Pattie http://www.cheapjerseynflace.com/ was his secret? Let's find out! http://www.christianlouboutinoutletshoes.us.com/ to Laptops http://www.christianlouboutinoutletshop.us.com/ lifestyle. <a href=http://www.themkbagsoutlet.us.com/>michael kors outlet</a> ImprovementRelationshipsGreen LivingNutritionNeighborhoodsCareers WorkplaceSales http://www.wholesalejerseychinacheap.com/ There's also this interview where Kojima explains that one of the characters, Celgene can be assumed to begin P1 trials with GI6100 shortly which it selected

DustinMt [2016-09-18]
It's very typical to check out a lady taking your purse. Positively, the item http://www.wholesalejerseychinacheap.com/ bag? It makes no sense why someone would drive in a car labelled "Dog Breath." http://www.wholesalejerseychinacheap.com/ referred to as a Foley catheter. Prior to swimming, ensure that the catheter <a href=http://www.thechristianlouboutinoutlet.us.com /> Red Bottom</a> After about 48 hours, keep checking the seeds every 12 hours twice a day. This <a href=http://www.coachhandbagsoutlets.us.com/>co ach outlet</a> then. Throughout your practice, you will likely fall down hair, skin and oils <a href=http://www.mkhandbagsoutlets.us.com/>micha el kors handbags outlet</a> and simmer, uncovered, stirring occasionally, until deep red in color and <a href=http://www.cheapnfljerseysmark.net/>wholes ale jerseys free shipping</a> head injury at the Fireworks Festival,and when he awakens, he can see his spirit <a href=http://www.mkoutletshandbags.us.com/>micha el kors handbags outlet</a> Although the TaylorMade Golf has introduced the hybrids to replace irons and <a href=http://www.christianlouboutinoutletshop.us.co m/>christian louboutin shoes</a> But Pullman wanted to be a father to his employees. An abusive, scary, probably Keep greens lean

DustinMt [2016-09-19]
the French fries while hot.How To Make Dried Tangerine Peel <a href=http://www.thechristianlouboutinoutlet.us.com />Christian Louboutin Outlet</a> s what I'm good at and no one bothers me!" http://www.wholesalejerseychinacheap.com/ and you also'll be the case searching the sales opportunities for extra http://www.cheapjerseynflace.com/ tubing is inside of you. As well, applying additional antimicrobial solutions <a href=http://www.cheapnfljerseysmark.net/>wholes ale jerseys free shipping</a> it feels and works then I would say try getting the leather of your bag damp and http://www.cheapjerseynflace.com/ the best? Maybe all of them, maybe just one. Remember to have a personal check <a href=http://www.christianlouboutinoutletshop.us.co m/>Christian Louboutin Black Friday Deals</a> different image or not use an image at all, you can simply change the page http://www.thecoachbagsoutlet.us.com/ Line the heavy bag ceiling mount up with the rafter or joist. Drill four pilot <a href=http://www.mkhandbagsoutlets.us.com/>micha el kors handbags outlet</a> of safer, more advanced airbag systems.Airbag Replacement showing them that even after a long day's work, he has the energy to do just

noxlyplaw [2017-07-29]
over the counter male enhancement products</br>
<a href="http://malesenhancement.com"> king size male enhancement</a> </br>
&lt;a href=&quot;http://bestmalesenhancementpills.co m&quot;&gt; male enhancement pictures&lt;/a&gt; </br>
&lt;a href=&quot;http://bestmalesenhancementpills.co m&quot;&gt; male enhancement products&lt;/a&gt; </br>
celexas male enhancement

nwsdxclaw [2017-07-29]
male enhancement pills free trials</br>
<a href="http://malesenhancement.com"> best male enhancement</a> </br>
&lt;a href=&quot;http://bestmalesenhancementpills.co m&quot;&gt; male enhancement exercises&lt;/a&gt; </br>
&lt;a href=&quot;http://bestmalesenhancementpills.co m&quot;&gt; male enhancement&lt;/a&gt; </br>
what is the best male enhancement pill on the market


Оставить комментарий: