在Gmail API中设置发件人名称(无需警告)

发布于 2025-01-27 06:16:21 字数 880 浏览 2 评论 0 原文

是,

  1. 如果我在create_message函数中的属性中添加消息['from'],那么发送gmail后会显示警告(“请注意此消息 - gmail无法验证它实际上来自。

我面临的问题 上面的问题是删除消息['来自']属性,因为它会自动从Creds Config File中检索详细信息

  1. 。无法设置发件人的名称(“ abc name”

因此 通过我可以实现这两件事。

创建功能看起来像这样

def create_message(sender, to, cc, subject, message_text):
message = MIMEText(message_text,'html')
message['to'] = to
message['from'] = sender
message['subject'] = subject
if str(cc) !='nan':
    message['cc'] = cc

pprint(message)
return {
    'raw': base64.urlsafe_b64encode(
        bytes(
            message.as_string(),
            "utf-8")).decode("utf-8")}

The problem I am facing is that

  1. If I add message['from'] in attribute in the create_message function then after sending Gmail shows a warning ("Be careful with this message - gmail could not verify that it actually came from .

The solution to the above problem is to remove message['from'] attribute as it automatically retrieves the details from creds config file. Once I remove the from attribute, the warning goes away.

  1. If I remove the message['from'] attribute, I am not able to set the Sender's Name ("ABC NAME" [email protected].
    Hence mail goes like [email protected] instead of ABC Name

Looking for a way through which I can achieve both the things.

Create Function looks like this

def create_message(sender, to, cc, subject, message_text):
message = MIMEText(message_text,'html')
message['to'] = to
message['from'] = sender
message['subject'] = subject
if str(cc) !='nan':
    message['cc'] = cc

pprint(message)
return {
    'raw': base64.urlsafe_b64encode(
        bytes(
            message.as_string(),
            "utf-8")).decode("utf-8")}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文