普通用户( 非码农 )在sendgrid 上选择 EMAIL API 还是 marketing campaign 呢? 两者都可选择吗 有wordpress
1条回答 默认 最新
关注
让阿豪来帮你解答,本回答参考chatgpt3.5编写提供,如果还有疑问可以评论或留言
建议普通用户选择发送邮件时使用sendgrid的EMAIL API,而使用marketing campaign则需要一些编程技能。因为EMAIL API更适合处理个性化的邮件发送,可以通过API接口方便地针对不同的用户群体发送不同的邮件内容。而marketing campaign则需要设计电子邮件,配置列表和集成系统,需要更多的技能。 在使用EMAIL API时,可以使用SendGrid提供的官方wordpress插件(https://sendgrid.com/docs/for-developers/sending-email/wordpress/),此插件可以让用户通过wordpress后台进行邮件发送设置,而无需编写任何代码。另外,如果需要更加复杂的邮件发送需求,也可以通过API文档编写自定义代码实现。 以下是SendGrid官方提供的一些EMAIL API使用示例代码: 发送简单的文本邮件:import os from sendgrid import SendGridAPIClient from sendgrid.helpers.mail import Mail message = Mail( from_email='from_email@example.com', to_emails='to@example.com', subject='Subject', plain_text_content='Email body') sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) response = sg.send(message)
发送html邮件:
import os from sendgrid import SendGridAPIClient from sendgrid.helpers.mail import Mail, HtmlContent message = Mail( from_email='from_email@example.com', to_emails='to@example.com', subject='Subject', html_content=HtmlContent('<strong>Email body</strong>')) sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) response = sg.send(message)
发送带附件的邮件:
import os from sendgrid import SendGridAPIClient from sendgrid.helpers.mail import Mail, Attachment, FileContent, FileName, FileType, Disposition with open('/path/to/file', 'rb') as f: data = f.read() file_content = base64.b64encode(data).decode() attachment = Attachment( FileContent(file_content), FileName('file.pdf'), FileType('application/pdf'), Disposition('attachment') ) message = Mail( from_email='from_email@example.com', to_emails='to@example.com', subject='Subject', plain_text_content='Email body', attachments=[attachment]) sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) response = sg.send(message)
解决 无用评论 打赏 举报