gpt4 book ai didi

python - Twilio 模块通过 Python 发送电子邮件内容

转载 作者:行者123 更新时间:2023-11-30 23:00:52 25 4
gpt4 key购买 nike

我正在尝试使用 Python 向自己发送短信。这是我的代码:

from twilio.rest import TwilioRestClient

account_sid = ""
auth_token = ""
client = TwilioRestClient(account_sid, auth_token)

message = client.messages.create(to="", from_="",
body=
"Some text here...\n"
"\n"
"Stats for this run through:"
"\n"
email_1
email_2
email_3
email_4
email_5
email_6
email_7
email_8
email_9
email_10
email_11
email_12
"\n"
"\n"
email_13
email_14
email_15
)

在上面的示例中,email_1-email_15 是我在其他地方定义的变量。当我尝试运行此代码时,出现以下错误:

    email_1
^
SyntaxError: invalid syntax

我正在尝试获取多行消息,email_1-15 由一些文本和一个动态变量组成,这些文本和动态变量从元组连接在一起形成字符串。

示例输出应该是:

Some text here...

Stats for this run through:

text_1: 1
text_2: 1
text_3: 1
text_4: 1
text_5: 1
text_6: 1
text_7: 1
text_8: 1
text_9: 1
text_10: 1
text_11: 1
text_12: 1
text_13: 1
text_14: 1
text_15: 1

谁能看出这里出了什么问题吗?

谢谢

最佳答案

以这种方式在代码中插入变量名在 Python 中是无效的语法。像这样的东西应该有效:

message = client.messages.create(to="", from_="",
body=
"Some text here...\n"
"\n"
"Stats for this run through:"
"\n" +
"\n".join([email_1, email_2, email_3, email_4, email_5, email_6, email_7,
email_8, email_9, email_10, email_11, email_12, email_13, email_14,
email_15])
)

我强烈建议您定义一个列表来包含电子邮件变量,因为它会使您的代码更加简单:

message = client.messages.create(to="", from_="",
body=
"Some text here...\n"
"\n"
"Stats for this run through:"
"\n" +
"\n".join(emails)
)

关于python - Twilio 模块通过 Python 发送电子邮件内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35103465/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com