I'm trying to send an appointment from ruby (rails) to Microsoft Outlook 2013.
When I'm sending an ICS file in the attachment, user have to open the file manually.
Looking for a way to send normal meeting request (user won’t need to open ICS to accept it).
I read the tutorial: http://knaveofdiamonds.com/post/50689213/sending-outlook-appointments-with-ruby
but it’s not working for me, user getting the following email:
--
Date: Tue, 27 May 2014 23:17:23 +0300
Message-ID: <5384f2d3b125b_90c30357c28514#Eric-PC.mail>
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: base64
Content-Disposition: inline
QSBSdWJ5IGNyZWF0ZWQgYXBwb2ludG1lbnQ=
--
Date: Tue, 27 May 2014 23:17:23 +0300
Message-ID: <5384f2d3b1e13_90c30357c2861e#Eric-PC.mail>
Mime-Version: 1.0
Content-Type: text/calendar;
charset=UTF-8;
method=request;
name=subject.ics
Content-Transfer-Encoding: quoted-printable
content-class: urn:content-classes:calendarmessage
BEGIN:VCALENDAR
VERSION:2.0
PRODID:icalendar-ruby
CALSCALE:GREGORIAN
BEGIN:VEVENT
DTSTAMP:20140527T201722Z
UID:abb15328-a6af-4c95-8e04-acdb9d6584e2
DTSTART:20140623T083000
DTEND:20140624T083000
CLASS:PRIVATE
DESCRIPTION:Have a long lunch meeting and decide nothing...
SUMMARY:Meeting with the man.
END:VEVENT
END:VCALENDAR
This is my ruby code
cal = Icalendar::Calendar.new
cal.event do |e|
e.dtstart = DateTime.civil(2014, 6, 23, 8, 30)
e.dtend = DateTime.civil(2014, 6, 24, 8, 30)
e.summary = "Meeting with the man."
e.description = "Have a long lunch meeting and decide nothing..."
e.ip_class = "PRIVATE"
e.uid = SecureRandom.uuid
end
Mail.defaults do
delivery_method :smtp, options
end
mail = Mail.new
mail.mime_version = "1.0"
mail.body = cal.to_ical
mail.from = 'ericfeldman93#gmail.com'
mail.to = 'ericfeldman93#gmail.com'
mail.subject = 'bla'
mail.content_type = "text/calendar"
mail.deliver
Any idea?
You should not send an ICS file as an attachment. Your whole message must have the content type of text/calendar and it should have a single part - text/calendar:
Date: Tue, 27 May 2014 23:17:23 +0300
Message-ID: <5384f2d3b125b_90c30357c28514#Eric-PC.mail>
Mime-Version: 1.0
Content-Type: text/calendar;
charset=UTF-8;
method=request;
name=subject.ics
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
content-class: urn:content-classes:calendarmessage
BEGIN:VCALENDAR
VERSION:2.0
PRODID:icalendar-ruby
CALSCALE:GREGORIAN
BEGIN:VEVENT
DTSTAMP:20140527T201722Z
UID:abb15328-a6af-4c95-8e04-acdb9d6584e2
DTSTART:20140623T083000
DTEND:20140624T083000
CLASS:PRIVATE
DESCRIPTION:Have a long lunch meeting and decide nothing...
SUMMARY:Meeting with the man.
END:VEVENT
END:VCALENDAR
Related
I have a Mailer class which inherits from ApplicationMailer, which in turn inherits from ActionMailer::Base. Ruby version is ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin15].
The Mailer class looks like the following:
class PurchaseOrderStatusMailer < ApplicationMailer
CONTACTS = {
JC: ['me#example.com'],
RM: ['me#example.com']
}
def daily_report_email(facility)
#facility = facility
ingredient_items = LineItem.ingredient.by_facility(facility)
#delivered_count = ingredient_items.by_date([7.days.ago, 7.days.from_now]).delivered.count
#partial_count = ingredient_items.by_date([7.days.ago, 1.day.ago]).partial.count
#late_count = ingredient_items.by_date([7.days.ago, 1.day.ago]).late.count
#expected_count = ingredient_items.by_date([Date.today, 7.days.from_now]).expected.count
mail(to: CONTACTS[facility.to_sym], subject: "#{facility} Daily Receipt Status - #{Date.today}")
end
end
ApplicationMailer looks like the following:
# frozen_string_literal: true
class ApplicationMailer < ActionMailer::Base
default from: 'notify#example.com'
def facility_email(facility)
emails = Rails.application.config_for(:emails)
(emails[facility] + emails["DEFAULT"]).flatten
end
end
The view is located at app/views/purchase_order_status_mailer/daily_report_email.html.erb.
When I open my Rails console and type PurchaseOrderStatusMailer.new.daily_report_email('JC').deliver, I see the following error:
NoMethodError: undefined method `empty?' for nil:NilClass
from /Users/me/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/actionview-5.0.4/lib/action_view/lookup_context.rb:215:in `normalize_name'
I tried passing a format block to the call to the mail helper with the same call, like so:
mail(to: CONTACTS[facility.to_sym], subject: "#{facility} Daily Receipt Status - #{Date.today}") do |format|
format.text { render plain: "Hey!" }
end
The above produced the following response, which appears to represent a successful email send:
Rendering text template
Rendered text template (0.0ms)
Sent mail to me#example.com (8.8ms)
Date: Mon, 25 Sep 2017 12:55:11 -0400
From: notify#example.com
To: me#example.com
Message-ID: <59c934efec401_1115b3fd69cc3f840917be#me-MBP.mail>
Subject: JC Daily Receipt Status - 2017-09-25
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Hey!
=> #<Mail::Message:70191029273300, Multipart: false, Headers: <Date: Mon, 25 Sep 2017 12:55:11 -0400>, <From: notify#example.com>, <To: ["me#example.com"]>, <Message-ID: <59c934efec401_1115b3fd69cc3f840917be#me-MBP.mail>>, <Subject: JC Daily Receipt Status - 2017-09-25>, <Mime-Version: 1.0>, <Content-Type: text/plain>, <Content-Transfer-Encoding: 7bit>>
I didn't actually receive an email, and I assume that means I don't have SMTP set up on my local machine, but the above response is encouraging. There was no stack trace apart from the error I posted above, so I tried digging into the Rails source code, and I saw that normalize_name inside lookup_context.rb gets called from within the args_for_lookup protected method, which in turn gets called by the ViewPaths module's find_all method. But beyond that it was hard to trace the call stack, as I couldn't find who the caller of find_all is.
My question is: what is wrong with the first call to mail?
EDIT 1: I also tried format.html { render html: "<h1>Hello Mikel!</h1>".html_safe } instead of the format.text option, as per the example here, and I got a similar success message.
I then tried adding a byebug statement inside normalize_name, to try and identify what the values of the parameters were on the successful email sends, but it looks like this method isn't getting called when a block is passed. That makes me suspect even more strongly that the problem is somehow related to my views. But I can't confirm that yet.
The issue is here
PurchaseOrderStatusMailer.new.daily_report_email('JC').deliver
remove the new i.e
PurchaseOrderStatusMailer.daily_report_email('JC').deliver
Because of the wrong object of its not able to deduce the template path/file
I was able to generate a success response (including my mailer's rendered template file) by passing template_path and template_name options to the original call to the mail helper, like so:
mail(
to: CONTACTS[facility.to_sym],
subject: "#{facility} Daily Receipt Status - #{Date.today}",
template_path: 'purchase_order_status_mailer',
template_name: 'daily_report_email')
This generated the following success response:
Rendering purchase_order_status_mailer/daily_report_email.text.erb
Rendered purchase_order_status_mailer/daily_report_email.text.erb (0.3ms)
Sent mail to me#example.com (12.1ms)
Date: Mon, 25 Sep 2017 15:18:25 -0400
From: notify#example.com
To: me#example.com
Message-ID: <59c9568121cec_11e943fee8503f82823542#me-MBP.mail>
Subject: JC Daily Receipt Status - 2017-09-25
Mime-Version: 1.0
Content-Type: multipart/alternative;
boundary="--==_mimepart_59c9568120033_11e943fee8503f8282341e";
charset=UTF-8
Content-Transfer-Encoding: 7bit
----==_mimepart_59c9568120033_11e943fee8503f8282341e
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Please find the receipt status for JC as of 09-25-2017:
=================================================================================================
...<lots more content, including ERB rendered into HTML>...
=> #<Mail::Message:70293683934580, Multipart: true, Headers: <Date: Mon, 25 Sep 2017 15:18:25 -0400>, <From: notify#example.com>, <To: ["me#example.com"]>, <Message-ID: <59c9568121cec_11e943fee8503f82823542#me-MBP.mail>>, <Subject: JC Daily Receipt Status - 2017-09-25>, <Mime-Version: 1.0>, <Content-Type: multipart/alternative; boundary="--==_mimepart_59c9568120033_11e943fee8503f8282341e"; charset=UTF-8>, <Content-Transfer-Encoding: 7bit>>
I'm a little confused about why I had to add these options, as the documentation doesn't make it clear that these are required and my templates and folders appear to be named correctly, but it worked and I have deadlines so I'm moving on. :-)
I am migrating an application from Rails 2.3 to Rails 3.1, the emails are not working, when i send an email with attachment i see a plain/text email with the encoded pdf content in the email instead of as an attachment.
here is the command i used to send email
ret = UserMailer.return_forms(#customer[:email], #store, id, #customer[:document]).deliver
here is the definition of returns_form, the return_forms is a method in UserMailer class (class UserMailer < ActionMailer::Base)
def return_forms(email, store, order, pdf_document_path)
load_smtp_settings("noreply")
#recipients = email
#subject = "#{business_name}: Return forms"
#body = "Please follow the instructions within the forms to return your merchandise. Thank You."
attachments['free_book.pdf'] = {mime_type: 'application/pdf',content: File.read(pdf_document_path) }
#from = email
#date = Time.zone.now
#headers = {}
end
I see the content as
--
Date: Mon, 10 Aug 2015 16:16:26 +0530
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-ID: <55c881028af96_48d43fe94782e9a0658aa#amol-desktop.mail>
Please follow the instructions within the forms to return your merchandise. Thank You.
--
Date: Mon, 10 Aug 2015 16:16:26 +0530
Mime-Version: 1.0
Content-Type: application/pdf;
charset=UTF-8
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename=free_book.pdf
Content-ID: <55c88102872ba_48d43fe94782e9a0657a0#amol-desktop.mail>
JVBERi0xLjQKJcfsj6IKNyAwIG9iago8PC9MZW5ndGggOCAwIFIvRmlsdGVy
IC9GbGF0ZURlY29kZT4+CnN0cmVhbQp4nH1W227bOBB991cM0AWqABZLUvc8
bTZNivTiuLUX2GKzD6xE22pk0aWktOnX75CSbUW+xEhkDufMGc4cjvIDKGFA
zad7puvRmy8JLKuRtYJejnyfghd5MQRBSIGjTY4W1srDkB+xeh4HHocQ92yM
clxzr7NFLD6w7fx6WOtn4gWhD2ewjEfeaZIeuHW0GUYxg3Nwn/rhGaI+vnVt
8wzhHN4PqX+GqQ+3njbTxIez8DhOzhD14dZzUM+j8MD3zxH14K3nIOZReEjp
The return_forms call should have a call for mail() method at the end. Something like:
mail(:from => your_from, :to => your_to, :subject => your_subject, :body => your_body)
It is also a good idea to enable mailer errors in your development.rb to see if any errors appear:
config.action_mailer.raise_delivery_errors = true
I have a rails application that is using Amazon SES service to send information emails to customers. In development environment this email functionality is working ok. However, when I run my application in my EC2 instance the emails are not sent anymore.
I have checked the logs, and everything looks good:
Rendered email_service/send_booking_request_customer_notification.html.erb (7.6ms)
Sent mail to cliente.yanpy#gmail.com (25.8ms)
Date: Mon, 03 Nov 2014 11:17:57 +0000
From: Yanpy <business#yanpy.com>
To: cliente.yanpy#gmail.com
Message-ID: <5457646572252_1be3fd803f643b45382f#ip-172-31-20-213.mail>
Subject: Nueva solicitud de reserva [MMSGORDH].
Mime-Version: 1.0
Content-Type: multipart/related;
boundary="--==_mimepart_5457646554c90_1be3fd803f643b4536a1";
charset=UTF-8
Content-Transfer-Encoding: 7bit
----==_mimepart_5457646554c90_1be3fd803f643b4536a1
Content-Type: multipart/alternative;
boundary="--==_mimepart_545764656fbba_1be3fd803f643b4537bb";
charset=UTF-8
Content-Transfer-Encoding: 7bit
----==_mimepart_545764656fbba_1be3fd803f643b4537bb
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: quoted-printable
[text-content]
----==_mimepart_545764656fbba_1be3fd803f643b4537bb
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE html>
[html-content]
----==_mimepart_545764656fbba_1be3fd803f643b4537bb--
----==_mimepart_5457646554c90_1be3fd803f643b4536a1
Content-Type: image/png;
charset=UTF-8;
filename=logo.png
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename=logo.png
Content-ID: <545764654ea73_1be3fd803f643b4535ba#ip-172-31-20-213.mail>
iVBORw0KGgoAAAANSUhEUgAAAWAAAAB5CAYAAAAHz/urAAAACXBIWXMAAAsT
AAALEwEAmpwYAAAKTWlDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVN3...
----==_mimepart_5457646554c90_1be3fd803f643b4536a1--
I have checked business#yanpy.com is a verified sender email address. I even have sent a test email from SES console from business#yanpy.com to cliente.yanpy#gmail.com and the email is sent and received.
However, when I send these emails programatically, everything looks good, but the emails are not received.
I fixed it. I have realized I was missing my smtp configuration for my test environment in Rails.
I added:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "email-smtp.eu-west-1.amazonaws.com",
:user_name => "************", # Your SMTP user here.
:password => "*************", # Your SMTP password here.
:authentication => :login,
:enable_starttls_auto => true
}
to my environments/test.rb config file in Rails and it worked.
I am trying to send xls file via ActionMailer.
mailer = ActionMailer::Base.mail(:to => "reciever#gmail.com", :from => "sender#gmail.com", :content_type=>"application/vnd.ms-excel", :body=> '')
mailer.attachments['filename.xls']= {mime_type: 'application/vnd.ms-excel', content: File.read("filePath.xls")}
mailer.deliver!
I am able to receive the mail as well.
But somehow the attachment is not correct, it shows up as noname and below is the content I get in the file (I am copy pasting the exact contents)
--
Date: Wed, 04 Jun 2014 23:33:48 +0530
Mime-Version: 1.0
Content-Type: application/vnd.ms-excel;
charset=UTF-8
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename=filename.xls
Content-ID: <538f5f82836992#C02L2178FFT3.gmail>
PGgzIHN0eWxlPSJmb250LXdlaWdodDpib2xkIj4gCiAgICBTaG93aW5nCiAg
ICBvcGVuCiAgICByZXF1ZXN0cwogICAgZnJvbQogICAgTm92IDIxLCAyMDEz
....
I am sure I am missing something simple, I am unable to figure out what. Can someone help?
Try this:--
mailer = ActionMailer::Base.mail(:to => "reciever#gmail.com", :from => "sender#gmail.com", :content_type=>"application/vnd.ms-excel", :body=> '')
mailer.attachments["filename.xls"]= File.read("filePath.xls")
mailer.deliver!
I'm working on an application with Rails 4 on Ruby 2.0.0. The application sends out an email after a registration in Devise.
This is the code that sends the email:
app/models/sponsor.rb:
after_create :send_email_to_admin
private
def send_email_to_admin
AdminMailer.new_sponsor_email(self).deliver
end
app/mailers/admin_mailer.rb
class AdminMailer < ActionMailer::Base
default to: '**removed**'
def new_sponsor_email(sponsor)
#sponsor = sponsor
p #sponsor
mail(subject: "New Sponsor Registration")
end
end
And this is the generated email from the log file:
Sent mail to **removed** (725.5ms)
Date: Mon, 02 Sep 2013 15:01:03 -0400
From: **removed**
To: **removed**
Message-ID: <5224e06f4dddd_2e5a3fa0452dcfd874597#centaur.mail>
Subject: New Sponsor Registration
Mime-Version: 1.0
Content-Type: multipart/alternative;
boundary="--==_mimepart_5224e06f4cca1_2e5a3fa0452dcfd87441a";
charset=UTF-8
Content-Transfer-Encoding: 7bit
----==_mimepart_5224e06f4cca1_2e5a3fa0452dcfd87441a
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
A new sponsor has signed up!
==========================
----==_mimepart_5224e06f4cca1_2e5a3fa0452dcfd87441a
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<!DOCTYPE html>
<html lang='en'>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type'>
</head>
<body>
<h1>A new sponsor has signed up!</h1>
</body>
</html>
----==_mimepart_5224e06f4cca1_2e5a3fa0452dcfd87441a--
when I try to test the code by creating a sponsor, I just get this error:
Net::SMTPSyntaxError in Devise::RegistrationsController#create
501 5.5.4 Invalid argument
My understanding is that this is typically because the email is and invalid email, but all of my emails are very simple, in the format of name#domain.tld and no-reply#domain.tld.
The issue seemed to be that I was using "domain" in my smtp_settings. When I removed that, I was able to send emails from both Mailgun and Gmail