Coder Social home page Coder Social logo

Comments (3)

tomek-ac avatar tomek-ac commented on July 17, 2024 1

Both ways should work. This works too in the example I gave:

    mail(to: to).attachments["appointment"] = { mime_type: "text/calendar", content: cal.to_ical }

Anyway, I'm glad you solved the issue!

from postmark-rails.

tomek-ac avatar tomek-ac commented on July 17, 2024

@akaspick I can't replicate the issue. I am able to send emails with iCal attachments and here's what I did:

  1. I created a new branch new Rails 7 app
  2. Added postmark-rails and icalendar to Gemfile
  3. Set up environment following environment variables:
export POSTMARK_SERVER_TOKEN=<YOUR TOKEN>
export DEFAULT_FROM=<YOUR FROM EMAIL ADDRESS>
export DEFAULT_TO=<YOUR TEST TO EMAIL ADDRESS>
  1. Added following to the config/application.rb:
    config.action_mailer.delivery_method = :postmark
    config.action_mailer.postmark_settings = { api_token: ENV.fetch("POSTMARK_SERVER_TOKEN") }
  1. Added a new mailer:
bin/rails g mailer Test email_with_attachment
# app/mailers/test_mailer.rb
class TestMailer < ApplicationMailer
  default from: ENV.fetch("DEFAULT_FROM")

  def email_with_attachment(to: ENV.fetch("DEFAULT_TO"))
    @greeting = "Hi"

    # Create a calendar with an event (standard method)
    cal = Icalendar::Calendar.new
    cal.event do |e|
      e.dtstart     = 1.day.from_now + 1.hour
      e.dtend       = 1.day.from_now + 3.hours
      e.summary     = "Some event"
      e.description = "With a description"
    end

    attachments["appointment"] = { mime_type: "text/calendar", content: cal.to_ical }

    mail to: to
  end
end
  1. And I can successfully send the emails with a command like this:
bin/rails r "TestMailer.email_with_attachment.deliver_now"

Could you give us more details on how you're sending the emails? It looks that there is an issue with configuring the stream. We'd need a bit more context to be able to help you.

from postmark-rails.

akaspick avatar akaspick commented on July 17, 2024

@tomek-ac I believe I've solved the issue...

I was specifying the attachment as
mail.attachments['appointment.ics'] = {mime_type: 'text/calendar', content: @appointment.to_ical}
but had to instead use
attachments['appointment.ics'] = {mime_type: 'text/calendar', content: @appointment.to_ical}

The former syntax works via test/specs and other mailers, but it didn't work when sending via postmark. The latter syntax works now for me without specifying mail at the start. The action mailer docs use the former syntax so there appears to be a bit of a compatibility issue: https://api.rubyonrails.org/classes/ActionMailer/Base.html#method-i-attachments

from postmark-rails.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.