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.
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)