当前位置: 首页>>代码示例>>Python>>正文


Python Message.attach方法代码示例

本文整理汇总了Python中mailer.Message.attach方法的典型用法代码示例。如果您正苦于以下问题:Python Message.attach方法的具体用法?Python Message.attach怎么用?Python Message.attach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mailer.Message的用法示例。


在下文中一共展示了Message.attach方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: sendmail

# 需要导入模块: from mailer import Message [as 别名]
# 或者: from mailer.Message import attach [as 别名]
def sendmail(mailto, subject, html='', text='', textfile='', htmlfile='', attachments=''):
    '''send mail'''
    if not mailto:
        print 'Error: Empty mailto address.\n'
        return

    mailto = [sb.strip() for sb in mailto.split(',')]
    if attachments:
        attachments = [att.strip() for att in attachments.split(',')] 
    else:
        attachments = []
    
    #USERNAME = hostname()
    subject = "%s-[%s]" % ( subject, hostname())

    message = Message(From=USERNAME, To=mailto, Subject=subject, attachments=attachments)
    message.Body = text
    message.Html = html
    message.charset = 'utf8'
    try:
        if htmlfile:
            message.Html += open(htmlfile, 'r').read()
        if textfile:
            message.Body += open(textfile, 'r').read()
    except IOError:
        pass

    for att in attachments:
        message.attach(att)

    sender = Mailer(SERVER,port=465, use_tls=True, usr=USERNAME, pwd=PASSWD)
    #sender = Mailer(SERVER)
    #sender.login(USERNAME, PASSWD)
    sender.send(message)
开发者ID:cychenyin,项目名称:windmill,代码行数:36,代码来源:mailman.py

示例2: message

# 需要导入模块: from mailer import Message [as 别名]
# 或者: from mailer.Message import attach [as 别名]
    def message(self, name, log_file=None, error=None, **kwargs):
        """Create an email for the given stage based upon the log file.

        If no log file is provided or it is False then the email's body will
        not include the log lines to examine, and it will not be attached. If
        an error object is given this will be used to indicate the stage
        failed.

        :stage: Name of the stage that was run.
        :log_file: Filename for the log file
        :error: Exception object that occurred.
        :returns: A Mailer message to send.
        """

        status = 'Succeeded'
        if error:
            status = 'Failed'

        kwargs = {'stage': name, 'status': status}
        subject = self.config['email']['subject'].format(**kwargs)
        to_address = kwargs.get('send_to', None) or self.config['email']['to']
        msg = Message(
            From=self.config['email']['from'],
            To=to_address,
            Subject=subject,
            Body=self.body(name, log_file, **kwargs)
        )

        compressed_log = self.compressed_log(log_file)
        if compressed_log:
            msg.attach(compressed_log)

        return msg
开发者ID:BGSU-RNA,项目名称:RNA-3D-Hub-core,代码行数:35,代码来源:email.py

示例3: sendMail

# 需要导入模块: from mailer import Message [as 别名]
# 或者: from mailer.Message import attach [as 别名]
def sendMail(item, hwp):
    sender = Mailer('smtp.gmail.com',use_tls=True)
    for to in MAILER_TO :
        sender.login(MAILER_USERNAME,MAILER_PASSWORD)
        message = Message(From='[email protected]', To=to)
        message.Subject = "가정통신문 :%s"%item['title'].encode('utf-8')
        message.Html = ""
        if hwp:
            message.attach(hwp)
        sender.send(message)
开发者ID:geekslife,项目名称:soongduk,代码行数:12,代码来源:soongduk.py

示例4: send_email

# 需要导入模块: from mailer import Message [as 别名]
# 或者: from mailer.Message import attach [as 别名]
def send_email(image):
	# Format email message
	message = Message(From=MAIL_FROM,To=MAIL_TO)
	message.Subject = MAIL_SUBJECT
	message.Html = MAIL_HTML
	message.Body = MAIL_BODY
	message.attach(image)

	# Send message to SMTP server
	sender = Mailer(SMTP_HOST)
	sender.send(message)
开发者ID:rickysaltzer,项目名称:lolock,代码行数:13,代码来源:video.py

示例5: send_reply

# 需要导入模块: from mailer import Message [as 别名]
# 或者: from mailer.Message import attach [as 别名]
    def send_reply(self, message, toAddress):
        sender = Mailer(host=settings.host, port=settings.port, usr=settings.username, 
                    pwd=settings.password, use_tls=settings.tls)
        email  = Message(From=message['fromAddress'], To=toAddress, Subject=message['subject'], CC=message['ccAddress'])
        email.Html = message['body']

        messageUploads = '{}/{}/attachments/'.format(self.uploadsBasePath, message['_id'])

        for upload in os.listdir(messageUploads):
            email.attach('{}{}'.format(messageUploads, upload))

        print 'Sending {} to {}'.format(message['subject'], toAddress)
        
        sender.send(email)
开发者ID:kennyledet,项目名称:Autocraig-Web,代码行数:16,代码来源:kennycraig.py

示例6: email_kindle_guardian

# 需要导入模块: from mailer import Message [as 别名]
# 或者: from mailer.Message import attach [as 别名]
def email_kindle_guardian(from_email, kindle_email):
    now = datetime.datetime.now()
    file_name = "gdn-" + format(now.year, "02d") + "-" + format(now.month, "02d") + "-" + format(now.day, "02d") + ".mobi"
    url = "http://mythic-beasts.com/~mark/random/guardian-for-kindle/" + file_name
    # Download the file!
    req = Request(url)

    try:
        f = urlopen(req)
        print "Downloading " + url
        # Download the file to tmp
        with open("/tmp/" + file_name, "w+") as local_file:
            local_file.write(f.read())

        # Yey!, we've downloaded the file. Email it!
        message = Message(From=from_email, To=[kindle_email], Subject="Guardian " + file_name)
        message.attach("/tmp/" + file_name)
        sender = Mailer("localhost")
        sender.send(message)
        print "Yey! I've sent today's Guardian to " + kindle_email

    except HTTPError, e:
        print e.code, url
开发者ID:mtrl,项目名称:email-kindle-guardian,代码行数:25,代码来源:email-kindle-guardian.py

示例7: Message

# 需要导入模块: from mailer import Message [as 别名]
# 或者: from mailer.Message import attach [as 别名]
msg2.To = "[email protected]"
msg2.Subject = "日本語の添付ファイルメール"
msg2.charset = "utf-8"

mailer.send([msg1, msg2])

msg = Message()
msg.From = "[email protected]"
msg.To = "[email protected]"
msg.Subject = "テキストメール"
msg.Body = "これは日本語のキストメールでございます。"
msg.charset = "utf-8"
mailer.send(msg)

msg3 = Message(From="[email protected]",
                  To=["[email protected]", "[email protected]"],
                  charset="utf-8")
msg3.Subject = "HTML with Attachment"
msg3.Html = """Hello, <b>日本語</b>"""
msg3.attach("picture.png")
mailer.send(msg3)

# now try specifying the MIME type
msg4 = Message(From="[email protected]",
                  To=["[email protected]", "[email protected]"],
                  charset="utf-8")
msg4.Subject = "HTML with Attachment (MIME type specified)"
msg4.Html = """Hello, please have a look at this image."""
msg4.attach("picture.png", mimetype="image/png")
mailer.send(msg4)
开发者ID:arunsingh,项目名称:mailer,代码行数:32,代码来源:use_mailer.py

示例8: int

# 需要导入模块: from mailer import Message [as 别名]
# 或者: from mailer.Message import attach [as 别名]
csv_file = csv.DictReader(open("BD.csv"))

for d in csv_file:
    if int(d["Perfil"]) is not 2:
        file_notsend.writerow(d)
        to =""
        continue
    if not "@" in d["Email"]:
        file_notsend.writerow(d)
        to=""
        continue
    else:
        to = d["Email"]

    m = Message(From= from_, To = to)
    m.attach("cote.gif","header")
    params = dict(
        razon_social=d["Descripcion"],
        numero_sap=d["ClaveSAP"],
        userid=d["UserName"],
        password=d["Password"]
    )
    str_html = str_html_back % params
    m.Subject = "NUEVA PAGINA WEB DE PROVEEDORES"

    m.Html = str_html
    m.Body = html2text.html2text(str_html).encode("utf8")
    try:
        sender.send(m)
        print "%s %s send"  % ( d["Email"], d["UserName"])
        file_send.writerow(d)
开发者ID:zodman,项目名称:sendemails,代码行数:33,代码来源:module1.py

示例9: send_email

# 需要导入模块: from mailer import Message [as 别名]
# 或者: from mailer.Message import attach [as 别名]
def send_email(ID):
	# Construct email, this is a biggie
	body = ""
	this_candidate_info = dict( g.conn.execute( select([g.candidates]).where(g.candidates.c.id == ID) ).fetchone().items() )

	# We have to figure out if this potential devil saw the questions before
	# This isn't fool proof of course, but can catch most attempts where they 
	# see the questions, close the window, research the answers, and try again.

	# Get a list of IDs that match the candidates email address, phone number
	# or (hesitated on this one) IP, and crucially those IDs in the DB that 
	# haven't completed the submission
	this_candidate_email = this_candidate_info['email']
	this_candidate_phone = this_candidate_info['phone']
	this_candidate_ip = this_candidate_info['ip']
	subject = "[Candidate] {0}".format(this_candidate_email)
	
	possible_candidates = g.conn.execute( select(['*']).where(
		and_(
			g.candidates.c.cv_uploaded == False,
			or_(
				g.candidates.c.email == this_candidate_email,
				g.candidates.c.phone == this_candidate_phone,
				g.candidates.c.ip    == this_candidate_ip,
			)
		)
	))
	
	attempts = []
	for candidate in possible_candidates:
		attempts.append( dict(candidate.items()) )

	attempts.append(this_candidate_info)
	# At this points, attempts[] has all the candidates attempts

	multiple_attempts = True if len(attempts) > 1 else False

	body += "Candidate info:\n"
	for attempt in attempts:
		if multiple_attempts:
			body += "--- Attempt ID {0} ---\n".format(attempt['id'])
		body += "- Name: {0}\n".format(attempt['name'])
		body += "- Email: {0}\n".format(attempt['email'])
		body += "- Phone: {0}\n".format(attempt['phone'])
		body += "- IP address: {0}\n".format(attempt['ip'])
		body += "- Browser: {0}\n".format(attempt['useragent'])
		body += "- Time: {0}\n".format(attempt['entry_date'])
		body += "\n"

	
	for code,title in [ ('basic_questions','Basic Questions'),  ('extra_questions','Extra Questions'), ('nontech_questions', 'Nontech Questions') ]:
		body += "_" * 60
		body += "\n"
		body += "{0}:\n\n".format(title)
		for attempt in attempts:
			if multiple_attempts:
				body += "--- Attempt ID {0} ---\n".format(attempt['id'])
			if attempt.get('{0}_start'.format(code), None)  and not attempt.get('{0}_end'.format(code), None):
				body += "The candidate saw the questions without attempting any on {0}\n\n".format(attempt['basic_questions_start'])
				continue
			# Now copy the .txt for this ID blindly
			body += get_answers(attempt['id'], '{0}.txt'.format(code))
			body += "\n"

	app.logger.debug(body)

	# Actually send the email:
	if not app.config['DEMO_MODE']:
		message = Message(From=app.config['MAIL_FROM'], To=app.config['MAIL_TO'])
		message.Subject = subject
		message.Body = body
		# Get attachments, all files in the repo ID
		path = "{0}/{1}/cv_upload".format(app.config['REPO_DIR'], this_candidate_info['id'])
		for filename in os.listdir(path):
			file_location = "{0}/{1}".format(path, filename)
			message.attach(file_location)
			app.logger.debug("Attaching {0}".format(file_location))
		sender = Mailer(app.config['MAIL_SERVER'])
		sender.send(message)
		return ""
	else:
		return body
开发者ID:rizvir,项目名称:upload-sievee,代码行数:84,代码来源:upload_sievee.py


注:本文中的mailer.Message.attach方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。