[Tutor] How to attach file with mail

Kirk Bailey deliberatus@my995internet.com
Thu, 13 Dec 2001 02:03:14 -0500


The project thus far does not handle mime m ultipart attachments- most
list servers do not. The footwe would mess it up. IF you want to pass an
attachment, do not use a footer on that list. I will have to include a
few lines to see if the footer files exist, and to skip that part of
code if they do not. Such a list would simply pass on the main protion
of the submuission, with the in line attachment sitting right there.

Would you like to look at a short letter with a short attachment?


ns# list testfile
Listing of file testfile in directory:/www/www.howlermonkey.net/cgi-bin
--------------begin listing of file 'testfile'-----------
From: Kirk Bailey <deliberatus@my995internet.com>
Organization: Silas Dent Memorial Cabal of ERIS Esoteric and hot dog
boiling society 
 so there.
X-Mailer: Mozilla 4.74 [en] (Win98; U)
X-Accept-Language: en
MIME-Version: 1.0
To: testcode@howlermonkey.net
Subject: test
Content-Type: multipart/mixed;
 boundary="------------C63C5C0E80A93D974E28BCA5"

This is a multi-part message in MIME format.
--------------C63C5C0E80A93D974E28BCA5
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

test
-- 
Respectfully,
             -Kirk D Bailey (C)2001
              Addme! icq #27840081
end
      My Sites:
      http://www.howlermonkey.net/ - free REAL email! list service soon!
      http://www.sacredelectron.org/ - Rants! Spleenvents!
      http://www.minorfish.org/ - The list server for some of us!

Message of the week:
R5L9W SDPQW UVN7V RUBWB I6HFP WVCUT VWRVL
W7812 LVH8V JBVK2 3CEJB TO8P3 FHFHG H7BFM
QID68 6DN6F 6M486 YQNCF JECQP 86CNP 86CTT
JIQPF ZPVGV DLFST DBUDI UIFNC BTUBS ETBOE
BTTGV DLUIF NSFBM IBSE!
--------------C63C5C0E80A93D974E28BCA5
Content-Type: text/html; charset=us-ascii;
 name="boo.html"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="boo.html"

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
   <meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
   <meta name="Author" content="Kirk Bailey">
   <meta name="GENERATOR" content="Mozilla/4.74 [en] (Win98; U)
[Netscape]">
   <title>composertest</title>
</head>
<body>
<font color="#FFCC00">this is a test</font><font color="#330033">
and is only a test<u> but should not be taken literally, this is not a
school.</u></font>
<br><font color="#330033"><u>worse, it is not all important</u> and is
not really important.</font>
<br><font color="#330033"></font>&nbsp;
</body>
</html>

--------------C63C5C0E80A93D974E28BCA5--
------------------end of listing---------------------


ns# 

Abhiram Singh Kushwah wrote:
> 
> Hi all,
>         How to attach a file with this code?
> 
> > #!/usr/local/bin/python
> >                                 # so the script is
> > executable
> > import smtplib                  # import the smtp
> > routines
> > import string                   # and string
> > manipulation stuff
> >
> > CRLF=("\r"+"\n")                        # we will be
> > tagging CRLF onto
> > several things.
> >                                         # so this is
> > handy.
> >
> > def prompt(prompt):
> >         return string.strip(raw_input(prompt))  #
> > prompt, get, strip,
> > return.
> >
> >
> > fromaddr = prompt("From: ")             # get the from
> > address.
> > toaddrs  = prompt("To: ")               # get the to
> > address.
> > subject = prompt("Subject: ")           # get the
> > subject.
> >
> > print "Enter message, end with ^D:"     # Add the From:
> > and To: headers
> > at the start!
> >
> > msg = "From: " + fromaddr + CRLF + "To: " + toaddrs +
> > CRLF + "Subject: "
> > + subject + CRLF +
> >  CRLF
> >
> > while 1:
> >         try:
> >                 line = raw_input()
> >         except EOFError:
> >                 break
> >         if not line:
> >                 break
> >         msg = msg + line + CRLF
> >
> > print type(msg)
> >
> > print "Message length is " , len(msg) , " bytes long."
> >
> > server = smtplib.SMTP('localhost')
> > server.set_debuglevel(1)
> > server.sendmail(fromaddr, toaddrs, msg)
> > server.quit()
> >
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 
Respectfully,
             -Kirk D Bailey (C)2001
              Addme! icq #27840081
end


Within the sweep of his sword, Each man is an Ubar.

http://www.howlermonkey.net/
http://www.sacredelectron.org/