sending an email with an attachment in ruby

  • Thread starter Matthew Margolis
  • Start date
M

Matthew Margolis

I would like to send email from a server running FreeBSD(TextDrive) to
my gmail account to make a weekly backup of my customer's website. The
attachment that I need to be able to send will be a tgz and will be
around 15 MBs. What are my options for constructing and sending this
mail via ruby?

Right now I am using PHPmailer for this job and it just isn't cutting it
now that the attachment is over 10 MBs. I checked out RAA and didn't
find anything that seemed to handle attachments well. Simplemail looked
to be the most promising but it doesn't seem to play nice on my server,
it just sat there eating up lots of resources.



Thank you,
Matthew Margolis
 
K

Kirk Haines

Right now I am using PHPmailer for this job and it just isn't cutting it
now that the attachment is over 10 MBs. I checked out RAA and didn't
find anything that seemed to handle attachments well. Simplemail looked
to be the most promising but it doesn't seem to play nice on my server,
it just sat there eating up lots of resources.

Use tmail. I send multipart MIME mail with it all the time (many hundreds,
daily). I have a class that sits in front of it using Forwardable and
implements some extra help for building multipart email, but it's nothing
terribly tricky. Email me offlist and I'll send you a copy and tell you the
couple of places you'll want to change what I did to make it more general
purpose.

And again, if there might be other interest, I can do the same thing with this
that I offered to do with my Webcache class and make a release seperate from
IOWA out of it as a standalone mini-project.


Kirk Haines
 
D

Daniel Kelley

Matthew Margolis said:
I would like to send email from a server running FreeBSD(TextDrive) to
my gmail account to make a weekly backup of my customer's website. The
attachment that I need to be able to send will be a tgz and will be
around 15 MBs. What are my options for constructing and sending this
mail via ruby?

I was hopting to show off something clever, but all I use is is 'metasend'.
The code below isn't complete, but it should give you an idea.


#
# Mail the output file as an attachment
#
def mail(addr, subject)

# no point if no address or records generated
if addr.nil? || @contact.length == 0 || @can_mail == false
return false
end

a = addr.split(",")

if a.length < 1
raise "no email addresses"
end

args = [
"-b",
"-S", "4000000",
"-f", @summary_output_file,
"-m", "Text/Plain; charset=us-ascii",
"-n",
"-f", @csv_output_file,
"-m", "application/octet-stream; name=\"#{@csv_output_file}\"",
"-D", @csv_output_file,
"-s", format_timestr(subject),
"-t", a[0]
]
if a.length > 1
args << "-c"
args << a[1..-1].join(",")
end
system("metasend", *args)
end

Pretty boring. But it has worked since February of 2004.

d.k.
 
E

Ezra Zygmuntowicz

Keep in mind that Gmail only allows attachments up to 10Mb in size.
So you will have to split it into 10Mb chunks and send multiple emails.
HTH
-Ezra Zygmuntowicz
WebMaster
Yakima Herald-Republic Newspaper
(e-mail address removed)
509-577-7732
 
E

Ezra Zygmuntowicz

Use tmail. I send multipart MIME mail with it all the time (many
hundreds,
daily). I have a class that sits in front of it using Forwardable and
implements some extra help for building multipart email, but it's
nothing
terribly tricky. Email me offlist and I'll send you a copy and
tell you the
couple of places you'll want to change what I did to make it more
general
purpose.

And again, if there might be other interest, I can do the same
thing with this
that I offered to do with my Webcache class and make a release
seperate from
IOWA out of it as a standalone mini-project.


Kirk Haines
Kirk -
I would be interested to see those classes as a separate
release. If you want you can contact me off list or keep it on list
for other peoples benefit.
Thanks-
-Ezra Zygmuntowicz
WebMaster
Yakima Herald-Republic Newspaper
(e-mail address removed)
509-577-7732
 
D

dave

--nextPart10601685.p2se8HFJ9s
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline



Why don't you use tar over ssh or rsync?=20

=2D-=20
here are more things in heaven and earth,
horatio, than are dreamt of in your philosophy.

--nextPart10601685.p2se8HFJ9s
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iQIVAwUAQvcBGKNg16HTgg0AAQK+Dw//ehHZtDnIKbzDdVcemqmDZdxGSLiVhQf2
naOY4JlIB0CF4Bt61WVoiWUcPzzH0btpnzPaYWEXULbrQtneIfQV/3kOVpg5vQhW
p/QMJk9DwGnFQvY0zzD4ENU45qQqlzN3K5BhRa7VnzqCWRBbV+lRNH9VNPjbbh3S
/+qpH6kp0YabbG8YUx/aIXI/2nolsLYleluv8QiCz9vWqo0gFGLVcrMrJl6v8WfG
kz17sNbpRAVb697+cxWRFoE6ZflvziRj1fFueXwcdXDKnr19Y7VFQQYJ8quB0Nhs
Gga4e9YPlhfZD0lCyZFYhe+QG4kVzuqtRQMpreEzSf4B3VgQKxFPok9iDSCB7kmR
V679v5gzsAZY8n1++AKkYUeAIb/NMb0RErZ+VNSkL1kIYz6jJM82/13fTPNlOIx5
lFmKJpvX6BhF8fhHZ0DM2Nh0F5nXaY2lvKk0g8ofzUWs5aNWxs/FonB7sPFSEjb6
jZa0VKziuJwrLrFDyp/dFbb8A9Di0z/raEb6q0t8NA8XTbCbTcY6qg3Whf66n0d7
W644I9uBzs+s6kMll19Srsqm3LZnme73YbL1jHGXvEkNP7ZQO0jvmtBl+MNe5AnZ
BjTKgkrN2Yy6R///xBc9G5U7zz6B3ohPOLzDGY5D+X2whEpGlkVDqPGxNa2mBtED
a4jj1D/Nmzs=
=xPq0
-----END PGP SIGNATURE-----

--nextPart10601685.p2se8HFJ9s--
 
M

Matthew Margolis

Ezra said:
Keep in mind that Gmail only allows attachments up to 10Mb in size.
So you will have to split it into 10Mb chunks and send multiple emails.
HTH
-Ezra Zygmuntowicz
WebMaster
Yakima Herald-Republic Newspaper
(e-mail address removed)
509-577-7732
Was this implemented in the last month or two? I have 11MB attachments
that I have sent through gmail.

Thank you,
Matthew Margolis
 
M

Matthew Margolis

dave said:
Why don't you use tar over ssh or rsync?
I am not quite sure what you are saying here. I am already using tar
via a system call in my ruby script. I don't have a local box that I
can just download the file to as I want to automate the process and I
have a laptop that is not always on. From what I understand rsync
doesn't do incremental backups and this is what I need, a tared file
representing the state of the site every week. And no I can't use
subversion as the client doesn't want restoring the backup to be
dependent on the host at all.

-Matthew Margolis
 
M

Matthew Margolis

Matthew said:
Was this implemented in the last month or two? I have 11MB
attachments that I have sent through gmail.

Thank you,
Matthew Margolis
Nevermind I found the blurb on gmail's site. I guess I am going to need
to figure out a new backup system.

-Matthew Margolis
 
E

Ezra Zygmuntowicz

Matthew Margolis wrote:


Nevermind I found the blurb on gmail's site. I guess I am going to
need to figure out a new backup system.

-Matthew Margolis
Mathew-
You can still do this with gmail. You just need to split the
tar.gz file into 10MB chunks. If you are on linux or OSX have a look
at $ man split. You can make the tar.gz backup of the whole htdocs
folder and then run it through split which can split it up into 10Mb
chunks then loop through and attach one chunk to each email until the
whole backup is complete. Then when you need to restore a backup you
just append the chunks together and untar/gzip just like normal. Let
me know how you come along on this script as I could use something
similar. Actually why don't you contact me off list and we can work
together to make this script? I'm sure some poeple would find it
useful and we can post it back to the list here once it is finished.
HTH-
-Ezra Zygmuntowicz
Yakima Herald-Republic
WebMaster
509-577-7732
(e-mail address removed)
 
D

dave

--nextPart2621708.EWGj18unY1
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline



|I don't have a local box that I can just download the file to=20
| - I want to automate the process =20
| - I have a laptop that is not always on.
Have you thought to use a rootshell account?

Can you use cookies to automate the process (detect ip) and send backup via=
=20
ssh?

if (maintainer_visit?() && time_to_backup?() )
tar cj mysitedir | ssh cookie.current_ip "cat > tarball"
end

=2D-=20
here are more things in heaven and earth,
horatio, than are dreamt of in your philosophy.

--nextPart2621708.EWGj18unY1
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iQIVAwUAQveOSaNg16HTgg0AAQLLFA/+OAdflJz5s1HMAC0Hu8I6DSfJs/zJpG7g
7Pog41LdYn24IYyVFsYxXtbuSKxDTSuWz726jdXNSDupmm+9ld6o0DfmoMNew2g8
DuiPimgu0aQV5aE2H9IzghXn840jexm1+b2CEKIrEIfJh0KucvpVYOLEUvRuUKbw
vWyrMJm03NRSJK+H5BEiGz7BoufZ9CC6Wx7U49b5OlSCDgfi1uWdicq1Hg7kNV9a
E/uR99+85QR0hnS0Q3H3QenWecrcxkPyO6uYpgWSg0r8L6zbuCE8AszzHwPJ7CCl
kv6hc/3E7rU8cLfSCxSbShq93yxb07Nvf2hZzidU+5QsiUpswNevr+8vadLoHIxw
LX/U1u1ZDNIYiX0s2P/7mbZj61oNu3DHfrAfHuvoVqAc2XueO3lr/DyAFr3ZoQye
GWe/IWeVi19I/I9RMjW/ATMr6htjgP2KW1YjkmP7GXKbs2EOc6GWalK2gZoUfRZL
jUFXAeYlkDtBkifRRCLLJ6nbUJHYt7ShxQkoNp5A9dl8qFRKbPqhYPrExHe7c2Q3
NlGXDi0NaGuleyJOGib7VZ3LOX8+WOMJNyqPEl810YI14X35BKSxJKNb9kKlMo95
Z6NnJDJPSoiL9R1pfHSNJM6qkVB89uZKUJ9/0JqJMc0ZYWsEZ3N+xwpWjwrCfKF8
xsRepo4ppFc=
=ToJP
-----END PGP SIGNATURE-----

--nextPart2621708.EWGj18unY1--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top