[issue9297] SMTP with Sqlite3 file attachment
New submission from Murilo da Silva : I'm sending e-mail using SMTP. This e-mail is sent with an Sqlite3 database attached. When I send the e-mail in the same domain the attachment arrives OK, but if I send it to a different domain it comes crashed!! The file is added with some base64 code...I don't have any ideia why! The code mail.py: import smtplib import os import mimetypes import base64 from email import encoders from email.message import Message from email.mime.base import MIMEBase from email.mime.nonmultipart import MIMENonMultipart from email.mime.multipart import MIMEMultipart from email.mime.application import MIMEApplication from email.mime.audio import MIMEAudio from email.mime.image import MIMEImage from email.mime.message import MIMEMessage from email.mime.text import MIMEText class SendMail: def __init__(self): self.body = [] self.attachments = [] def add_body(self, _text, _subtype='plain', _charset='us-ascii'): part = MIMEText(_text+"\n", _subtype, _charset) self.body.append(part) def add_attach(self, _file_path, _subtype='octet-stream', _encoder=encoders.encode_base64, **_params): path = _file_path ctype, encoding = mimetypes.guess_type(path) if ctype is None or encoding is not None: ctype = 'application/octet-stream' maintype, subtype = ctype.split('/', 1) if maintype == 'text': fp = open(path) part = MIMEText(fp.read(), _subtype=subtype) fp.close() elif maintype == 'image': fp = open(path, 'rb') part = MIMEImage(fp.read(), _subtype=subtype) fp.close() elif maintype == 'audio': fp = open(path, 'rb') part = MIMEAudio(fp.read(), _subtype=subtype) fp.close() else: fp = open(path, 'rb') part = MIMEBase(maintype, subtype) part.set_payload(fp.read()) fp.close() # Encode the payload using Base64 encoders.encode_base64(part) part.set_payload(part.get_payload().decode()) part.add_header('Content-Disposition', 'attachment', filename = path.split(os.sep)[-1]) self.attachments.append(part) def send_now(self, mail_from, mail_to, subject, multipart_subtype='mixed', host=None, port=25, auth=False, user="", passw=""): msg = MIMEMultipart(multipart_subtype) msg['Subject'] = subject msg['From'] = mail_from if type(mail_to) is list: msg['To'] = ", ".join(mail_to) else: msg['To'] = mail_to for b in self.body: msg.attach(b) for att in self.attachments: msg.attach(att) try: mailserver = smtplib.SMTP(host, port) #mailserver.set_debuglevel(1) mailserver.ehlo() mailserver.starttls() mailserver.ehlo() if auth: mailserver.login(user, passw) mailserver.sendmail(mail_from, mail_to, msg.as_string()) mailserver.close() return True except Exception as e: print(e) return False The database to attach is in the final. The example: s = SendMail() s.add_body("test") s.add_attach(os.path.abspath("test.db")) s.send_now("t...@domain1.com", "t...@domain2.com", "test", host="smtp.domain1.com", port=25, auth=True, user="user", passw="pass") -- components: Library (Lib) files: test.db messages: 110707 nosy: murilobr priority: normal severity: normal status: open title: SMTP with Sqlite3 file attachment type: behavior versions: Python 3.1 Added file: http://bugs.python.org/file18056/test.db ___ Python tracker <http://bugs.python.org/issue9297> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9297] SMTP with Sqlite3 file attachment cross-domain problem
Changes by Murilo da Silva : -- title: SMTP with Sqlite3 file attachment -> SMTP with Sqlite3 file attachment cross-domain problem ___ Python tracker <http://bugs.python.org/issue9297> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9297] SMTP cross-domain with Sqlite3 file attached problem
Changes by Murilo da Silva : -- title: SMTP with Sqlite3 file attachment cross-domain problem -> SMTP cross-domain with Sqlite3 file attached problem ___ Python tracker <http://bugs.python.org/issue9297> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9297] SMTP with Sqlite3 file attached problem
Changes by Murilo da Silva : -- title: SMTP cross-domain with Sqlite3 file attached problem -> SMTP with Sqlite3 file attached problem ___ Python tracker <http://bugs.python.org/issue9297> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9297] SMTP with Sqlite3 file attached problem
Murilo da Silva added the comment: SOLVED!! MAIL SERVER BAD CONFIGURED. Thanks and sorry. -- status: open -> closed ___ Python tracker <http://bugs.python.org/issue9297> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9297] SMTP with Sqlite3 file attached problem
Murilo da Silva added the comment: It's not just a bad configured server. If I send the file with a mail client the file is sent ok. But Im having a problem just with my server. For example: 1 - If i send the file attached here test.db (SQLite3) from a gmail server to a yahoo server, the e-mail arrives ok. 2 - If i send the file test.db from my mail server to my mail server, the e-mail arrives ok too (independent of the account name). 3 - If i send the file test.db from gmail to my mail server the file arrives with bigger size (4kb original - 5.1kb with problem) The log to the first (1) situation: send: 'ehlo mmac.local\r\n' reply: b'250-mx.google.com at your service, [189.5.249.91]\r\n' reply: b'250-SIZE 35651584\r\n' reply: b'250-8BITMIME\r\n' reply: b'250-STARTTLS\r\n' reply: b'250 ENHANCEDSTATUSCODES\r\n' reply: retcode (250); Msg: b'mx.google.com at your service, [189.5.249.91]\nSIZE 35651584\n8BITMIME\nSTARTTLS\nENHANCEDSTATUSCODES' send: 'STARTTLS\r\n' reply: b'220 2.0.0 Ready to start TLS\r\n' reply: retcode (220); Msg: b'2.0.0 Ready to start TLS' send: 'ehlo mmac.local\r\n' reply: b'250-mx.google.com at your service, [189.5.249.91]\r\n' reply: b'250-SIZE 35651584\r\n' reply: b'250-8BITMIME\r\n' reply: b'250-AUTH LOGIN PLAIN XOAUTH\r\n' reply: b'250 ENHANCEDSTATUSCODES\r\n' reply: retcode (250); Msg: b'mx.google.com at your service, [189.5.249.91]\nSIZE 35651584\n8BITMIME\nAUTH LOGIN PLAIN XOAUTH\nENHANCEDSTATUSCODES' send: 'AUTH PLAIN AG11cmlsb2JyQGdtYWlsLmNvbQA2NHglOCp3Vnc4OQ==\r\n' reply: b'235 2.7.0 Accepted\r\n' reply: retcode (235); Msg: b'2.7.0 Accepted' send: 'mail FROM: size=5963\r\n' reply: b'250 2.1.0 OK h41sm27362860qcz.25\r\n' reply: retcode (250); Msg: b'2.1.0 OK h41sm27362860qcz.25' send: 'rcpt TO:\r\n' reply: b'250 2.1.5 OK h41sm27362860qcz.25\r\n' reply: retcode (250); Msg: b'2.1.5 OK h41sm27362860qcz.25' send: 'data\r\n' reply: b'354 Go ahead h41sm27362860qcz.25\r\n' reply: retcode (354); Msg: b'Go ahead h41sm27362860qcz.25' data: (354, b'Go ahead h41sm27362860qcz.25') send: 'Content-Type: multipart/mixed; boundary="===0772040488=="\r\nMIME-Version: 1.0\r\nSubject: teste\r\nFrom: muril...@gmail.com\r\nto: murilosilv...@yahoo.com.br\r\n\r\n--===0772040488==\r\ncontent-type: text/plain; charset="us-ascii"\r\nMIME-Version: 1.0\r\nContent-Transfer-Encoding: 7bit\r\n\r\nteste\r\n\r\n--===0772040488==\r\nContent-Type: application/octet-stream\r\nMIME-Version: 1.0\r\nContent-Transfer-Encoding: base64\r\nContent-Disposition: attachment; filename="test.db"\r\n\r\nU1FMaXRlIGZvcm1hdCAzAAQAAQEAQCAgCAIBAAABAA0DAloAA3gDJgJaAAA AAACBSQMHFx8fAYJhdGFibGVtYWlsX3NlbnRtYWlsX3NlbnQEQ1JFQVRFIFRBQkxFIG1haWxfc2VudChpZCBJTlRFR0VSIFBSSU1BUlkgS0VZIEFVVE9JTkNSRU1FTlQsIGJrcF9kb25lX2lkIElOVEVHRVIsIHRvX21haWwgVkFSQ0hBUig1MCksIHNlbnRfYXQgREFURVRJTUUsIEZPUkVJR04gS0VZKGJrcF9kb25lX2lkKSBSRUZFUkVOQ0VTIGJrcF9kb25lKGlkKSlQAgYXKysBWXRhYmxlc3FsaXRlX3NlcXVlbmNlc3FsaXRlX3NlcXVlbmNlA0NSRUFURSBUQUJMRSBzcWxpdGVfc2VxdWVuY2UobmFtZSxzZXEpgQUBBxcdHQGBXXRhYmxlYmtwX2RvbmVia3BfZG9uZQJDUkVBVEUgVEFCTEUgYmtwX2RvbmUoaWQgSU5URUdFUiBQUklNQVJZIEtFWSBBVVRPSU5DUkVNRU5ULCBmaWxlX25hbWUgVkFSQ0hBUig1MCksIGRvd25sb2FkX2F0IERBVEVUSU1FKQ0DA5EAA9sDtgOR A
[issue9297] SMTP with Sqlite3 file attached problem
Murilo da Silva added the comment: r.david.murray, if more info is needed, please send me what kind. -- ___ Python tracker <http://bugs.python.org/issue9297> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9297] SMTP with Sqlite3 file attached problem
Murilo da Silva added the comment: Ok, let me try. I'm sending a mail using Python, as you can see the code in the first message. I'm sending a file which is a SQLite database. When I send the file from my SMTP server to any other or from any server to mine the file doesn't arrive as test.db attached here, but it arrives like test_problem.db. But it arrives ok if I send from gmail to yahoo for example. I want some help to discover what kind of problem is happening. If Python is the problem or the server! But how can I say that my server has a problem if when I send this same file from my server no any other the file arrives ok. The question is have something to do with Python to solve? Is it a bug? Do you understand my point? Thanks you very much for your time. -- ___ Python tracker <http://bugs.python.org/issue9297> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9297] SMTP with Sqlite3 file attached problem
Murilo da Silva added the comment: "If Python is the problem or the server! But how can I say that my server has a problem if when I send this same file from my server no any other the file arrives ok." The phrase above I want to say that when I send the same file using a mail client as Mail from Mac OSX, the file arrives ok. -- ___ Python tracker <http://bugs.python.org/issue9297> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9297] SMTP with Sqlite3 file attached problem
Murilo da Silva added the comment: I upload two files (test.db and test_problem.db). The test.db is an SQLite which works ok (application/octet-stream), if I send it from: - gmail to my server - my server to gmail - yahoo to my server - my server to yahoo using my python program to send mail with the file test.db attached, it arrives as the example test_problem.db uploaded. But if I send test.db using a Mail Client by the 4 ways above, instead of my python program it arrives as test.db. Do you understand?? Thank you for your time. -- ___ Python tracker <http://bugs.python.org/issue9297> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com