在rails3中制作简报的最佳方式是什么?

时间:2022-09-15 20:51:04

Is there a gem to do this, and if not, what is the best approach. I'm assuming i'd store the emails in a newsletter database, and would want a form that emails everyone at once. thanks!

有没有宝石可以做到这一点,如果没有,最好的方法是什么。我假设我将电子邮件存储在时事通讯数据库中,并且需要一个可以同时通过电子邮件发送给所有人的表单。谢谢!

3 个解决方案

#1


12  

No gem for this that I know of.

我所知道的没有宝石。

Actually, due to processing issues, the best way would be to use external bulk email service provider via provider's API.

实际上,由于处理问题,最好的方法是通过提供商的API使用外部批量电子邮件服务提供商。

However, building your own newsletter system is no different from building your regular MVC. Only addition are mailers and mailer views.

但是,构建自己的新闻稿系统与构建常规MVC没有什么不同。只有添加邮件和邮件的视图。

(1) So you create model that deals with registration data (:name, :email, :etc...) and model that deals with newsletter itself.

(1)因此,您创建处理注册数据的模型(:name,:email,:etc ...)和处理简报本身的模型。

(2) Controller that deals with it (CRUD) + (:send). Send takes each recipient, sends data to mailer which creates email and then sends it.

(2)处理它的控制器(CRUD)+(:发送)。发送接收每个收件人,将数据发送到邮件程序,然后发送它。

def send
 @newsletter = Newsletter.find(:params['id'])
 @recipients = Recipient.all
 @recipients.each do |recipient|
   Newsletter.newsletter_email(recipient, @newsletter).deliver
 end
end

(3) Mailer builds an email, makes some changes in each email if you want to do something like that and returns it to controller action send for delivery.

(3)Mailer构建一个电子邮件,如果你想做这样的事情,在每封电子邮件中做一些更改并将其返回到控制器动作发送以进行传递。

class Newsletter < ActionMailer::Base
  default :from => "my_email@example.com", :content_type => "multipart/mixed"

  def newsletter_email(recipient, newsletter)
    # these are instance variables for newsletter view
    @newsletter = newsletter
    @recipient = recipient
    mail(:to => recipient.email, :subject => newsletter.subject)
  end
end

(4) Ofc, you need mailer views which are just like regular views. Well in multipart there is:

(4)Ofc,您需要与常规视图一样的邮件视图。好的多部分有:

  • newsletter_email.html.erb (or haml)
  • newsletter_email.html.erb(或haml)

  • newsletter_email.txt.erb

    When you want to send both html and text only emails. Instance variables are defined in mailer ofc.

    当您要发送html和纯文本电子邮件时。实例变量在邮件程序中定义。

And... that is it. Well you could use delayed job to send them since sending more than several hundred emails can take a while. Several ms times n can be a lot of time.

而且......就是这样。那么你可以使用延迟工作发送它们,因为发送超过几百封电子邮件可能需要一段时间。几个ms时间n可能是很多时间。

Have fun.

#2


3  

Please check the maktoub gem there is a blog post over it.

请检查maktoub gem上面有一篇博文。

#3


0  

No gem that I know of too and building on @Krule's answer, here's a screencast of setting up mailers in Rails.

我也不知道宝石,并以@Krule的答案为基础,这是一个在Rails中设置邮件的截屏视频。

How to create, preview and send email from your rails app

如何从rails应用程序创建,预览和发送电子邮件

I was looking for something similar when I found this. I think with a bit of customization, it can easily be used to create newsletter emails too.

当我发现这个时,我正在寻找类似的东西。我认为通过一些自定义,它也可以轻松地用于创建新闻通讯电子邮件。

Save money! Spend somewhere else.

存钱!花在其他地方。

#1


12  

No gem for this that I know of.

我所知道的没有宝石。

Actually, due to processing issues, the best way would be to use external bulk email service provider via provider's API.

实际上,由于处理问题,最好的方法是通过提供商的API使用外部批量电子邮件服务提供商。

However, building your own newsletter system is no different from building your regular MVC. Only addition are mailers and mailer views.

但是,构建自己的新闻稿系统与构建常规MVC没有什么不同。只有添加邮件和邮件的视图。

(1) So you create model that deals with registration data (:name, :email, :etc...) and model that deals with newsletter itself.

(1)因此,您创建处理注册数据的模型(:name,:email,:etc ...)和处理简报本身的模型。

(2) Controller that deals with it (CRUD) + (:send). Send takes each recipient, sends data to mailer which creates email and then sends it.

(2)处理它的控制器(CRUD)+(:发送)。发送接收每个收件人,将数据发送到邮件程序,然后发送它。

def send
 @newsletter = Newsletter.find(:params['id'])
 @recipients = Recipient.all
 @recipients.each do |recipient|
   Newsletter.newsletter_email(recipient, @newsletter).deliver
 end
end

(3) Mailer builds an email, makes some changes in each email if you want to do something like that and returns it to controller action send for delivery.

(3)Mailer构建一个电子邮件,如果你想做这样的事情,在每封电子邮件中做一些更改并将其返回到控制器动作发送以进行传递。

class Newsletter < ActionMailer::Base
  default :from => "my_email@example.com", :content_type => "multipart/mixed"

  def newsletter_email(recipient, newsletter)
    # these are instance variables for newsletter view
    @newsletter = newsletter
    @recipient = recipient
    mail(:to => recipient.email, :subject => newsletter.subject)
  end
end

(4) Ofc, you need mailer views which are just like regular views. Well in multipart there is:

(4)Ofc,您需要与常规视图一样的邮件视图。好的多部分有:

  • newsletter_email.html.erb (or haml)
  • newsletter_email.html.erb(或haml)

  • newsletter_email.txt.erb

    When you want to send both html and text only emails. Instance variables are defined in mailer ofc.

    当您要发送html和纯文本电子邮件时。实例变量在邮件程序中定义。

And... that is it. Well you could use delayed job to send them since sending more than several hundred emails can take a while. Several ms times n can be a lot of time.

而且......就是这样。那么你可以使用延迟工作发送它们,因为发送超过几百封电子邮件可能需要一段时间。几个ms时间n可能是很多时间。

Have fun.

#2


3  

Please check the maktoub gem there is a blog post over it.

请检查maktoub gem上面有一篇博文。

#3


0  

No gem that I know of too and building on @Krule's answer, here's a screencast of setting up mailers in Rails.

我也不知道宝石,并以@Krule的答案为基础,这是一个在Rails中设置邮件的截屏视频。

How to create, preview and send email from your rails app

如何从rails应用程序创建,预览和发送电子邮件

I was looking for something similar when I found this. I think with a bit of customization, it can easily be used to create newsletter emails too.

当我发现这个时,我正在寻找类似的东西。我认为通过一些自定义,它也可以轻松地用于创建新闻通讯电子邮件。

Save money! Spend somewhere else.

存钱!花在其他地方。