how can i change the real file extension of executable binary to send that file through gmail smtp protocol (all in python).
Example: "binary" to "binary.jpg"
I'll try this:
import gzip, shutil
src = open('3c7983cb70e9630cc4ee2fe3e1fb16c2', 'rb')
dest = gzip.open('3c7983cb70e9630cc4ee2fe3e1fb16c2.gz.jpg', 'wb')
shutil.copyfileobj(src, dest)
but when I try to send it via gmail smtp happens to this:
smtplib.SMTPDataError: (552, '5.7.0 Our system detected an illegal attachment on your message. Please\n5.7.0 visit http://mail.google.com/support/bin/answer.py?answer=6590 to\n5.7.0 review our attachment guidelines. n18sm433437wbh.23')
Thancks in advance.
According to Google's Policy, binary files are banned.
Gmail won't accept these types of files even if they are sent in a zipped
(.zip, .tar, .tgz, .taz, .z, .gz) format. If this type of message is sent to
your Gmail address, it is bounced back to the sender automatically.
So Google is unzipping your file and most likely checking the file headers to determine the file type (not relying on the extension provided. To get around this you could try uploading it as a password protected ZIP file, since google wouldn't be able to crack it open to scan the contents, assuming they allow that. Another option would be to encrypt the file before sending it, possibly even a very simple XOR encryption might be enough to get past the filtering. You would then need to decrypt upon retrieving the file.
Related
I'm struggle with one script using Python.
I'm trying to create a function that saves message with attachment as a .eml file.
Attachment is a excel file that is stored in my local folder.
Right now i have this code that displays good template to send, but it doesn't save this message as a eml file.
It is empty message
def save_mail():
outlook=win32.Dispatch("Outlook.Application")
olNs = outlook.GetNamespace("MAPI")
mail=outlook.CreateItem(0)
mail.To="email#email.com"
mail.Subject="TEST TEST"
mail.HTMLBody = "<p>TEST HTML</p>"
attachment=(file_path)
mail.Attachments.Add(attachment)
mail.SaveAs(path_file + '.eml', 9)
save_mail()
I don't know how I should solve this problem. Please help :)
The Outlook object model doesn't provide any property or method to save the item using the EML file format. EML, short for electronic mail or email, is a file extension for an email message saved to a file in the Internet Message Format protocol for electronic mail messages. It is the standard format used by Microsoft Outlook Express as well as some other email programs, but not Outlook. You may consider using third-party libraries such as Redemption for saving items using the EML file format.
Outlook Object Model does not allow to export in the MIME (EML) format.
You can either build EML file from the scratch (it is a text file) one property at a time, or you can use a library like Redemption (I am its author) - its SafeMailItem and RDOMail objects support olRfc822 format in the SaveAs method in addition to the formats supported by Outlook.
Is there any possibility or any library to log in to a given mail and recover a list of messages for a given sender?
I mean the situation in which I provide an e-mail address, based on this address, all messages in the inbox are filtered, and I am returned to the list of e-mails or the user's last message.
I use flask-mail to send emails, but I don't think it is possible to recover the list of messages.
You should check the standard mailbox library. It provides functionalities to read mailboxes stored on disk using the most popular mailbox file formats (Maildir, mbox, MH, Babyl, and MMDF at the time of this writing).
Be warned, nowaday, for performance, reasons many mail clients are using embedded database engines to store emails. SQLite being popular choice, you can also try the sqlite3 library.
Finally, You will also find exotic file formats like Mork. For that, you will have to write your own parser or turn to PyPy to search if someone has already done the work for you.
As a personal note, if your email client allows changing its storage backend, you may consider switching to a well know text-based storage format for your emails--it definitely helps in case of disaster recovery
As an example, I am using Thunderbird and set it up to use the mbox file format. So I can iterate over the message of my Junk folder that way:
>>> path = '~/.thunderbird/4tuag540.default/ImapMail/ssl0.ovh-1.net/INBOX.sbd/Junk'
>>> from mailbox import mbox
>>> junk = mbox(path)
>>> for message in junk:
... # Prinf the "From" header:
... print(message['From'])
...
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.
I'm writing a script in Python that saves attachments from Gmail, only from unseen emails. To save on bandwidth I want to make sure that every file only gets downloaded once.
-I can't check the folder where I save them, because the file could be removed already, and then it shouldn't download again. (The scripts accesses the Inbox read_only, so it doesn't mark the email as read. As soon as the script runs again it will download the same attachments again, until the email gets marked read via another channel.)
-Right now I save the filename to a sqlite database, but there's 2 problems: I haven't figured out how to check the database for the filename the next time I run the script, and there's also a chance that somewhen down the line an attachment arrives with the same filename, which then wouldn't get downloaded.
What's a safe and scalable way to make sure I don't download the files more than once?
There are several open source projects in Python that already perform this task very well. Why don't you take a look at OfflineIMAP and getmail's source code. Also, if you're just trying to backup your GMail account, I suggest you use one of those rather than rolling your own...
You could not only save the filename to the database but save, for example, the Date:-header of the mail, too. (Or any combination of headers of which you are sure that they define a mail uniquely).
You could fetch the headers for the message, and use the message's Date and/or Message-Id header value to construct a "unique id prefix" for all of the attachments in that message. Then create a key of the form [unique_id]_[filename], check if that key exists in your database or filesystem. If not, download all attachments for that message, and save each with the modified unique id key.
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.