Email open notification - ruby on rails

前端 未结 3 2154
醉话见心
醉话见心 2020-12-08 11:31

If I will send 100 email to the registered user and I want to know if users open email or not

How can I do this using Ruby on Rails?

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-08 11:56

    The only way to do this, is to use html email with a tracker image. You need to include a user specific image into the code.

    class TrackingController < ApplicationController
      def image
        # do something with params[:id]
        send_file "/path/to/an/image"
      end
    end
    

    add the following route:

    # Rails 2
    map.tracking_image "tracking_image/:id.gif", :controller => 'tracking', :action => image
    
    # Rails 3
    match 'products/:id', :to => 'tracking#image', :as => "tracking_image"
    
    # Rails 4 (match without verb is deprecated)
    get 'producsts/:id' => 'tracking#image', as: 'tracking_image'
    # or
    match 'producsts/:id' => 'tracking#image', as: 'tracking_image', via: :get
    

    in your email template something like this:

    <%= image_tag tracking_image_url(@user.id) %>
    

    But be aware, that this it's not guaranteed that the user reads the email and loads the image, some email clients don't load images, until the user wants to. And If he doesn't you can't do anything about this. Also if the user uses text mail only this won't work neither.

提交回复
热议问题