當前位置: 首頁>>代碼示例>>Python>>正文


Python Mail.set_from_name方法代碼示例

本文整理匯總了Python中sendgrid.Mail.set_from_name方法的典型用法代碼示例。如果您正苦於以下問題:Python Mail.set_from_name方法的具體用法?Python Mail.set_from_name怎麽用?Python Mail.set_from_name使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sendgrid.Mail的用法示例。


在下文中一共展示了Mail.set_from_name方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: SGEmailClient

# 需要導入模塊: from sendgrid import Mail [as 別名]
# 或者: from sendgrid.Mail import set_from_name [as 別名]
class SGEmailClient(object):

	def __init__(self):
		self.email_config = SendGridConfiguration.objects.all()[:1].get()
		self.sg = SendGridClient(self.email_config.api_key)
		self.message = Mail()
		self.message.set_from(self.email_config.email_from)
		self.message.set_from_name(self.email_config.email_from_name)
		self.message.set_subject(self.email_config.email_subject)

	def send_report_email(self, email, report):
		template_config = TemplateReport.objects.all()[:1].get()
		user = get_object_or_404(User, pk=email)
		logger.info(user)
		html = unicode(template_config.html_template).format(
			user_name=user.first_name,
		)
		self.message.add_to(user.email)
		self.message.add_to_name(user.first_name)
		self.message.set_html(html)

		if report['report']:
			self.message.add_attachment_stream(
				report['name'] , report['report']
			)

		status, msg = self.sg.send(self.message)
		logger.info('{0} - {1}'.format(status, msg))
開發者ID:roofcat,項目名稱:ivr-support,代碼行數:30,代碼來源:sendgrid_client.py

示例2: EmailClient

# 需要導入模塊: from sendgrid import Mail [as 別名]
# 或者: from sendgrid.Mail import set_from_name [as 別名]
class EmailClient(object):

    def __init__(self):
        self.sg = SendGridClient(SG_API_KEY)
        self.message = Mail()
        self.message.set_from(SG_FROM)
        self.message.set_from_name(SG_FROM_NAME)

    def send_sg_email(self, correo):
        # valores de envío
        self.message.add_to(correo.correo)
        self.message.add_to_name(correo.nombre_cliente)
        self.message.set_subject(correo.asunto)
        self.message.set_html(correo.html)
        # valores personalizados
        unique_args = {
            'empresa': correo.empresa,
            'rut_receptor': correo.rut_receptor,
            'rut_emisor': correo.rut_emisor,
            'tipo_envio': correo.tipo_envio,
            'tipo_dte': correo.tipo_dte,
            'numero_folio': correo.numero_folio,
            'resolucion_receptor': correo.resolucion_receptor,
            'resolucion_emisor': correo.resolucion_emisor,
            'monto': correo.monto,
            'fecha_emision': correo.fecha_emision,
            'fecha_recepcion': correo.fecha_recepcion,
            'estado_documento': correo.estado_documento,
            'tipo_operacion': correo.tipo_operacion,
            'tipo_receptor': correo.tipo_receptor,
        }
        self.message.set_unique_args(unique_args)
        # Validacion de adjuntos
        if correo.attachs:
            for adjunto in correo.attachs:
                adj = AttachModel.query(ancestor=adjunto).get()
                self.message.add_attachment_stream(adj.nombre, adj.archivo)
        # enviando el mail
        status, msg = self.sg.send(self.message)
        # imprimiendo respuesta
        logging.info(status)
        logging.info(msg)

    def send_mail_to_user_attach(self, correo):
        # valores de envío
        self.message.add_to(correo['email'])
        self.message.add_to_name(correo['user_name'])
        self.message.set_subject(correo['subject'])
        self.message.set_html(correo['html'])
        if correo['attach']:
            self.message.add_attachment_stream(correo['attach']['name'], correo['attach']['file'])
        status, msg = self.sg.send(self.message)
        # imprimiendo respuesta
        logging.info(status)
        logging.info(msg)
開發者ID:roofcat,項目名稱:etracking,代碼行數:57,代碼來源:mail_client.py

示例3: config_mail

# 需要導入模塊: from sendgrid import Mail [as 別名]
# 或者: from sendgrid.Mail import set_from_name [as 別名]
def config_mail():
    message = Mail()
    message.add_to("<[email protected]>")
    message.add_to_name("Kumar, Palani")
    message.set_from("[email protected]")
    message.set_from_name("Kavin");
    message.set_subject("Test message.,")
    message.set_text("Test text")
    message.set_html("<i><b>Test HTML</b></i>")
    message.set_replyto("[email protected]")
    message.set_date(rfc822.formatdate())
    return message
開發者ID:kapalani,項目名稱:test-sendgrid-api,代碼行數:14,代碼來源:test.py

示例4: send_email

# 需要導入模塊: from sendgrid import Mail [as 別名]
# 或者: from sendgrid.Mail import set_from_name [as 別名]
def send_email(subject='Test email', from_email='[email protected]', from_name='D. Goodwin', recipients=['[email protected]'], text_body='Hello from Flask', html_body='Hello from <b>Flask</b>'):
	from sendgrid import SendGridClient, Mail
	api_key = 'm3tr0pl4c3s'
	api_user = 'metroplaces'
	sendgrid = SendGridClient(username=api_user, password=api_key, 
		raise_errors=True,
		host='http://api.sendgrid.com',
		port=80,
		)

	message = Mail()
	message.add_to(recipients)
	message.set_from(from_email)
	message.set_from_name(from_name)
	message.set_subject(subject)
	message.set_text(text_body)
	message.set_html(html_body)

	try:
		sendgrid.send(message)
	except Exception as e:
		print "fail: %s" %(e)
開發者ID:LACMTA,項目名稱:places,代碼行數:24,代碼來源:extensions.py


注:本文中的sendgrid.Mail.set_from_name方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。