Question

I'm using the Pony gem to send emails. Assuming that I have both options open to me, is there a memory advantage to using :smtp or :sendmail?

Option 1: smtp

Here, Ruby connects directly to the SMTP server.

Pony.mail(
  :to => 'you@example.com',
  :via => :smtp,
  :via_options => {
    :address        => 'smtp.yourserver.com',
    :port           => '25',
    :user_name      => 'user',
    :password       => 'password',
    :authentication => :plain, # :plain, :login, :cram_md5, no auth by default
    :domain         => "localhost.localdomain" # the HELO domain provided by the client to the server
  })

Option 2: sendmail

Here, the local sendmail binary is spawned.

Pony.mail(
  :to => 'you@example.com',
  :via => :sendmail,
  :via_options => {
    :location  => '/path/to/sendmail',
    :arguments => '-t'
  })

In particular, I'm concerned about loading the entire contents of a file into memory before attaching it - but this seems to be necessary in both modes:

Pony.mail([...], :attachments => {"foo.zip" => File.read("path/to/foo.zip")})

This is similar to Sendmail vs SMTP, but those answers don't cover my question.

Was it helpful?

Solution

I maintain the Pony gem.

How big are the files you're sending over email? I don't think there's going to be much difference in memory usage between the transport methods.

If you have to send large files, I would use a different transport method, I don't generally send large files over smtp.

You could also try using the mail library directly:

https://github.com/mikel/mail

It may give you better performance for large files.

If that doesn't work, you may have to resort to calling uuencode and piping the output to mail (ie uuencode file.dat | mail foo@bar.com)

OTHER TIPS

First of all, Pony defaults to sendmail, so i'm guessing until you know that you need smtp (which is only the case on machines without sendmail, which also is determined by pony itself), i would just go for the defaults.

On another note: Since you're worried about system load, i would also suggest sendmail. This is because you're ruby/rails application will send the system load (attachment) over to sendmail, which probably will resolve the problem of too much memory load, faster than ruby running smtp itself would.

But to be honest, i don't think that there is too much difference between both version memory load wise, since both receive the attachments directly. Since you are talking about emails, i don't assume you are talking about hundreds of megabyte files, right?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top