473,395 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

MIME attachments, and alternatives

Hello

I am writing a program that sends simple text files to a remote
device.

the files have to be in the format textX.dat where X = numbers in the
range 0 up to 10 depending upon the situation. these files are stored
in a directory called attachments.

The files themselves are single line affairs in ascii.

the files have to be sent in base64.

the final email has a simple subject line, to and from addresses,
and the attachments.

so far so good, I have written the program to do this, don't laugh
here it comes.

the print statements are just there so that i can follow whats going
on at the moment.

--------------------------------------------------------------------------------------

import os
import smtplib
import mimetypes

from email import Encoders
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
def send_dat_files(subject_matter,serial,fromAddr,toAd dr):

base = os.getcwd()
print base
attachpath = base+'\\attachments'

if not os.path.exists(attachpath):
os.mkdir(attachpath)

# Create the enclosing (outer) message

if subject_matter == 'SU':
subjectstring = 'KKK_KRDS1_'+serial+'_SU'

outer = MIMEMultipart()
outer['Subject'] = subjectstring
outer['To'] = toAddr
outer['From'] = fromAddr

outer.add_header('Content-Description','Remote Management System')

outer.epilogue = ''

fileNames=[f for f in os.listdir(attachpath)]
for fileName in fileNames:
path = attachpath+'\\'+fileName
f=open(path,"rb")
bodytext = f.read()
f.close()
ctype, encoding = mimetypes.guess_type(path)
maintype, subtype = ctype.split('/', 1)
if maintype == 'text':
msg = MIMEText(bodytext)

else:
print 'we got a problem here'
break

Encoders.encode_base64(msg)
# Set the filename parameter
filestart,extension = fileName.split('.',1)
fileName = filestart+'.dat'
msg.add_header('Content-Disposition', 'attachment',
filename=fileName)
outer.attach(msg)

# Now send the message
s = smtplib.SMTP('smtp.paradise.net.nz')
print 'connecting'

s.sendmail(fromAddr, toAddr, outer.as_string())
print 'sent email'
s.quit()

sender = email@address
copieraddr = email@address
send_dat_files('SU', '65AN88888',sender,copieraddr)
_____________________________________
questions are:

1. you may note that i have to change the file extension to .dat,
this is a requirement of the receiving device, when i do that to the
file attachment directly, the encoding does not work. any idea why?

2. the attachment files will be generated by anothe bit of code that
i am writing, it strikes me as being a bit clunky to wirte these to an
extenal folder then copy then in to the above, is there anywhay that
i can take a string, then pretend that it is a file and attach it to
the email?

sorry if this is a bit long.

look forward to hearing from anyone

kind regards

bill ramsay.
Jul 18 '05 #1
0 1356

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Alberto | last post by:
I am struggling with the php mail function so to allow a multipart mime settings where both the message and any set of attachments can be allowed. Teorically, I'd know how to do. I build up my...
3
by: Erik Rosenbach | last post by:
I have a question about how to parse out mime from a message. I have email messages that are stored in a database table and these messages have mime headers embedded within them. How can I parse...
1
by: John B. Kim | last post by:
I am working on the code below: ****************************************************** use strict; use MIME::Lite; use Net::SMTP; my $from = 'steve@earthlink.net'; my @addweek1 =...
1
by: NM | last post by:
I need an advise on how to proceed. My understanding is that .net doesn't support mime and attachment web services. First question, is that true? If thats true, is there any tip or how-to...
1
by: Mad Scientist Jr | last post by:
I am writing a simple POP email reader in asp.net (vb.net) - I have the entire message read into a string variable. Can someone explain how to parse the message and save any MIME attachments out to...
3
by: flo | last post by:
hi, i have to develop a web service client (must be .net, currently i'm using c# with wse3) for a java service. the java service uses mime attachments for up- and download of files. i googled...
1
by: fabrizio.viggiani | last post by:
I need to send a mail message to an SMTP server. The .net framework provides System.Net.Mail namespace to send an email: - Build a System.Net.Mail.MailMessage and send it using SmtpClient The...
0
by: andreas.baus | last post by:
Hello. I'm trying to build a client using .NET/C# that is capable of communicating with an existing Webservice written in Java using Apache Axis. Now, I've encountered a problem trying to...
3
by: Steven Allport | last post by:
I am working on processing eml email message using the email module (python 2.5), on files exported from an Outlook PST file, to extract the composite parts of the email. In most instances this...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.