How To Create a draft email? - python

I want to write a python that can sends data to a draft message, but NOT Send the mail directly.
Situation:
I'm a 3D animator. After done some shots, we need to send email(not internet, just in our company) to Lighting Team.
So we have some mail form, but sometimes we need to fix some words manual(version,texture..etc).
like below:
Shot Name : XXXX_seqXXX_scXXX
File Locate(hair + cloth) : please import X:\XX\XX\XX\XXX_ABC.ma
File include:
XXX_hair **(use version 1)**
XXX_cloth
ZZZ_cloth **(No texture)**
any problem please tell me.
Thanks.
Ezylryb
Question is:
Now I can write into a file, but I don't know how to open mail software(win7 Livemail) and create a new mail has these content. I'm try to use smtplib, but it will send mail directly..
Could anyone help me??
Many Thanks!!!!
Ezylryb
==============================
Finally, I write HTML code into a .html file, and a eml file with email address + Title + CC, and use os.startfile to open both files.
And I can copy/paste to draft email ^O^.
Coz we need some chinese words, so use big5 code in eml, and use qupori module to decode MIME words to Chinese words in html file.

A "draft" is a feature which your email client (in this case Win7 livemail) implements by itself. It's more or less just an email in a mailbox that the client hasn't sent yet. Mail folders like your "outbox" etc. are similar.
It's not something that Python has access to. If the mail client uses a standard mailbox format, you might be able to create the email and write it into the mailbox using mailbox module. If not, the best you can do is to write out your draft email into a file and then open that in your mail client and manually edit it.

Related

Python / Email processing: How to get the date an attachment was created?

I have a Python program that will read an Outlook inbox using these Python libraries:
1. IMAPClient
2. email
I want to know if it is possible to get the date the email attachment was created.
I don't see anything in email headers that stand out. I can get the date an email was sent (or forwarded), but it is the case when an email is forwarded that prompts this question.
I want to get the date of the attachment inside the email. If anyone has done this, and has a full working code snippet to share, it would be greatly appreciated.
I have done several searches, looked carefully through email headers, looked at the two library documentation I am using (IMAPClient, and email), and see nothing that stands out that would lead to a solution.
Some file formats include this, most don't, some may. For example the EXIF data in some JPEG files includes it. To read that you'll need an EXIF library, not an IMAP library. Microsoft Word files include a creation date, IIRC that's mandatory for that format, but again you'll need a type-specific library.
IMAP is merely the channel through which you download the data you want to examine.

Read through an email and parse it into strings with python

I am wondering if it is possible to read through an email and parse the subject of the email into a string. I have a device that sends an email to specific inbox every time there is an error with the device. I want a script to read through the email as soon as it arrives in the inbox and get the device ID from the subject line and store it into a string. I was thinking I could use python because there are email modules for it, and it is what I'm most comfortable with. Would this be possible in Python? Or any other language for that matter? I have looked online, but I could not find anything that pertains to what I want it to do. Is this even possible? Thanks!

python CGI email dynamic output as a text file attachment

I am trying to send an email using python that has the standard To From, body, etc. However this is where my question comes in. My python script takes information in a string and manipulates it(adds,removes, formats, etc) I am trying to take this output and send it as an attachment on-the-fly. I know I can dump the output to a text file and then attach it to the email. However, due to the security of this CGI script I cannot write to the CGI directory. Is there a way to dynamically create a textfile object and send it as an attachment?
Using Python SMTP module.
I cannot create a traditional static text file due to permissions. I would like to see if Python is able to create a text file upon execution that i can populate with data and then attach to the email smtp module.
The last example on this page shows how to create and send multi-part MIME message that contains text and HTML parts using the smtplib andemail modules. It should be easily adaptable to your need to send a message as an attachment (ideally the attachment should have a content-type of message/rfc822).
Are you using smtplib and email.mime.multipart modules? the attach() method of the MIMEMultipart class accepts chunk of data to be attached, not a file.

Deleting the most recently received email via Python script?

I use Gmail and an application that notifies me if I've received a new email, containing its title in a tooltip. (GmailNotifier with Miranda-IM) Most of the emails I receive are ones I don't want to read, and it's annoying having to login to Gmail on a slow connection just to delete said email. I believe plugin is closed source.
I've been (unsuccessfully) trying to write a script that will login and delete the 'top' email (the one most recently received). However this is not as easy I thought it would be.
I first tried using imaplib, but discovered that it doesn't contain any of the methods I hoped it would. It's a bit like the dbapi spec, containing only minimal functionality incase the imap spec is changed. I then tried reading the imap RFC (rfc3501). Halfway through it, I realized I didn't want to write an entire mail client, so decided to try using pop3 instead.
poplib is also minimal but seemingly has what I need. However pop3 doesn't appear to sort the messages in any order I'm familiar with. I have to either call top() or retr() on every single email to read the headers if I want to see the date received.
I could probably iterate through every single message header, searching for the most recent date, but that's ugly. I want to avoid parsing my entire mailbox if possible. I also don't want to 'pop' the mailbox and download any other messages.
It's been 6 hours now and I feel no closer to a solution than when I started. Am I overlooking something simple? Is there another library I could try? (I found a 'chilkat' one, but it's bloated to hell, and I was hoping to do this with the standard library)
import poplib
#connect to server
mailserver = poplib.POP3_SSL('pop.gmail.com')
mailserver.user('recent:YOURUSERNAME') #use 'recent mode'
mailserver.pass_('YOURPASSWORD') #consider not storing in plaintext!
#newest email has the highest message number
numMessages = len(mailserver.list()[1])
#confirm this is the right one, can comment these out later
newestEmail = mailserver.retr(numMessages)
print newestEmail
#most servers will not delete until you quit
mailserver.dele(numMessages)
mailserver.quit()
I worked with the poplib recently, writing a very primitive email client. I tested this with my email server (not gmail) on some test emails and it seemed to work correctly. I would send yourself a few dummy emails to test it out first.
Caveats:
Make sure you are using 'recent
mode':
http://mail.google.com/support/bin/answer.py?answer=47948
Make sure your Gmail account has POP3
enabled: Gmail > Settings >
Forwarding and POP/IMAP > "Enable POP
for all mail"
Hope this helps, it should be enough to get you going!

Parsing All Mail from Mailbox File in Python

Maybe I'm going about this the wrong way, but I want to parse a single "catch all" email inbox via Python. I see the email module and I can make it parse an individual email, but what I want to do is open (for example) /var/spool/mail/catchall and parse all of the individual messages inside it. Opening that file and running the parser over it treats the whole thing as one giant email. How would I break it into individual messages?
Alternatively: is this A Bad Idea, given I'm going to want to delete the messages when I'm done with them? I'm tying this route instead of POP/ IMAP only because the server support isn't available right now.
You'll want to use mailbox to actually go through the mailbox.

Categories

Resources