<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: attachment code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 26 Jul 2008 17:33:00 GMT</pubDate>
    <description>DZone Snippets: attachment code</description>
    <item>
      <title>Email in Bash</title>
      <link>http://snippets.dzone.com/posts/show/4868</link>
      <description>//Bash email&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/bin/bash&lt;br /&gt;&lt;br /&gt;function email&lt;br /&gt;{&lt;br /&gt;echo "this is a test" | mail -s "test" "$1"&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;if [ "$1" = "" ]; then&lt;br /&gt;echo "nothing in param"&lt;br /&gt;else&lt;br /&gt;echo "sending mail"&lt;br /&gt;&lt;br /&gt;#emailing attachment&lt;br /&gt;#uuencode statsNbaAllStarSim statssim | mail -s "test attachement" atayebali@foxsports.com&lt;br /&gt;#uuencode &lt;filename that will be send&gt; &lt;name for attached file that is sent&gt; |&lt;br /&gt;&lt;br /&gt;#passing the param to function&lt;br /&gt;email $1&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 11 Dec 2007 00:58:01 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4868</guid>
      <author>aniline (Aniline)</author>
    </item>
    <item>
      <title>Send Email in Python with Text File Attachment</title>
      <link>http://snippets.dzone.com/posts/show/3910</link>
      <description>// description of your code here&lt;br /&gt;Send an email in python with a text attachment. You can change the attachment type by adjusting the part.startbody label in the attachment section (ie, 'image/jpg' or whatever)&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import smtplib, sys, MimeWriter, StringIO, base64&lt;br /&gt;import os&lt;br /&gt;def mail(serverURL=None, sender='', to='', subject='', text=''):&lt;br /&gt;    """&lt;br /&gt;    Usage:&lt;br /&gt;    mail('somemailserver.com', 'me@example.com', 'someone@example.com', 'test', 'This is a test')&lt;br /&gt;    """&lt;br /&gt;    message = StringIO.StringIO()&lt;br /&gt;    writer = MimeWriter.MimeWriter(message)&lt;br /&gt;    writer.addheader('Subject', subject)&lt;br /&gt;    writer.startmultipartbody('mixed')&lt;br /&gt;&lt;br /&gt;    # start off with a text/plain part&lt;br /&gt;    part = writer.nextpart()&lt;br /&gt;    body = part.startbody('text/plain')&lt;br /&gt;    body.write(text)&lt;br /&gt;&lt;br /&gt;    # now add an attachment&lt;br /&gt;    part = writer.nextpart()&lt;br /&gt;    part.addheader('Content-Transfer-Encoding', 'base64')&lt;br /&gt;    body = part.startbody('text/plain')&lt;br /&gt;    base64.encode(open('myfile.txt', 'rb'), body)&lt;br /&gt;&lt;br /&gt;    # finish off&lt;br /&gt;    writer.lastpart()&lt;br /&gt;&lt;br /&gt;    # send the mail&lt;br /&gt;    smtp = smtplib.SMTP(serverURL)&lt;br /&gt;    smtp.sendmail(sender, to, message.getvalue())&lt;br /&gt;    smtp.quit()&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 26 Apr 2007 17:23:42 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3910</guid>
      <author>minitotoro (Natalie)</author>
    </item>
    <item>
      <title>Returning A File As An Attachment From JSP</title>
      <link>http://snippets.dzone.com/posts/show/2096</link>
      <description>// This is truly a snippet. It's a small piece of code you use&lt;br /&gt;// within a JSP file to make sure that the file you are&lt;br /&gt;// returning is not interpreted by the browser. You use this&lt;br /&gt;// when you want to return a TXT file, JPG or other file that&lt;br /&gt;// the browser might open on its own rather than offer a &lt;br /&gt;// dialog to the user so it can be saved.&lt;br /&gt;//&lt;br /&gt;// Note: In this example I'm returning a text file so I set &lt;br /&gt;// the MIME type of the response to text/plain, but you need &lt;br /&gt;// to make sure it matches the type of data you are returning.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;response.setContentType("text/plain");&lt;br /&gt;&lt;br /&gt;response.setHeader("Content-Disposition", "attachment; filename=\"test.txt\"");&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 25 May 2006 01:04:59 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2096</guid>
      <author>JohnMunsch (John Munsch)</author>
    </item>
    <item>
      <title>Send email with attachment(s) in Python</title>
      <link>http://snippets.dzone.com/posts/show/2038</link>
      <description>Can't remember if I wrote this or found it on the Web or a combination, so I won't take credit per se -- I'm just posting it as reference.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import smtplib&lt;br /&gt;import os&lt;br /&gt;from email.MIMEMultipart import MIMEMultipart&lt;br /&gt;from email.MIMEBase import MIMEBase&lt;br /&gt;from email.MIMEText import MIMEText&lt;br /&gt;from email.Utils import COMMASPACE, formatdate&lt;br /&gt;from email import Encoders&lt;br /&gt;&lt;br /&gt;def send_mail(send_from, send_to, subject, text, files=[], server="localhost"):&lt;br /&gt;  assert type(send_to)==list&lt;br /&gt;  assert type(files)==list&lt;br /&gt;&lt;br /&gt;  msg = MIMEMultipart()&lt;br /&gt;  msg['From'] = send_from&lt;br /&gt;  msg['To'] = COMMASPACE.join(send_to)&lt;br /&gt;  msg['Date'] = formatdate(localtime=True)&lt;br /&gt;  msg['Subject'] = subject&lt;br /&gt;&lt;br /&gt;  msg.attach( MIMEText(text) )&lt;br /&gt;&lt;br /&gt;  for f in files:&lt;br /&gt;    part = MIMEBase('application', "octet-stream")&lt;br /&gt;    part.set_payload( open(file,"rb").read() )&lt;br /&gt;    Encoders.encode_base64(part)&lt;br /&gt;    part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(f))&lt;br /&gt;    msg.attach(part)&lt;br /&gt;&lt;br /&gt;  smtp = smtplib.SMTP(server)&lt;br /&gt;  smtp.sendmail(send_from, send_to, msg.as_string())&lt;br /&gt;  smtp.close()&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 16 May 2006 00:15:43 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2038</guid>
      <author>timmorgan (Tim Morgan)</author>
    </item>
  </channel>
</rss>
