无法使用 Ruby 使用 Mailgun 发送多行纯文本电子邮件
Unable To Send Multiline Plaintext Email With Mailgun using Ruby
我使用两个文件通过 Mailgun 发送消息。他们是:
email_sender.rb
message_text.rb
第一个的代码是:
require './message_text.rb'
fromLabel = "Email Guy"
fromAddress = "digital@mail.*****.com"
toAddress = "info@*****.net"
subject = "An Invitation"
cmd = "curl -s --user 'api:key-*****' https://api.mailgun.net/v3/mail.*****.com/messages -F from='" + fromLabel + " <" + fromAddress + ">' -F to='" +toAddress + "' -F subject='" + subject + "' -F text='" + $message + "'"
wasGood = system (cmd)
第二个文件的代码是:
$message = "Line One Text."
+ "\n" + "\n" + "And Line Two Text!"
当我测试发送电子邮件时,到达我的测试帐户收件箱的邮件如下。
Line One Text.
如果您 运行 带有 ruby -w
的代码,即:启用警告,它会警告:warning: possibly useless use of + in void context
,并带有相应的行号,指向:
$message = "Line One Text."
+ "\n" + "\n" + "And Line Two Text!"
Ruby 的礼貌用语:"well, it's not a syntax error, but it does not make sense to me."
试试
$message = "Line One Text.
And Line Two Text!" # or: "Line One Text.\n\nAnd Line Two Text!"
所以我通过将所有内容放在一行中来让它工作。
$message = "Line One Text!" + "\n" + "\n" + "Line Two Text!"
我使用两个文件通过 Mailgun 发送消息。他们是:
email_sender.rb
message_text.rb
第一个的代码是:
require './message_text.rb'
fromLabel = "Email Guy"
fromAddress = "digital@mail.*****.com"
toAddress = "info@*****.net"
subject = "An Invitation"
cmd = "curl -s --user 'api:key-*****' https://api.mailgun.net/v3/mail.*****.com/messages -F from='" + fromLabel + " <" + fromAddress + ">' -F to='" +toAddress + "' -F subject='" + subject + "' -F text='" + $message + "'"
wasGood = system (cmd)
第二个文件的代码是:
$message = "Line One Text."
+ "\n" + "\n" + "And Line Two Text!"
当我测试发送电子邮件时,到达我的测试帐户收件箱的邮件如下。
Line One Text.
如果您 运行 带有 ruby -w
的代码,即:启用警告,它会警告:warning: possibly useless use of + in void context
,并带有相应的行号,指向:
$message = "Line One Text."
+ "\n" + "\n" + "And Line Two Text!"
Ruby 的礼貌用语:"well, it's not a syntax error, but it does not make sense to me." 试试
$message = "Line One Text.
And Line Two Text!" # or: "Line One Text.\n\nAnd Line Two Text!"
所以我通过将所有内容放在一行中来让它工作。
$message = "Line One Text!" + "\n" + "\n" + "Line Two Text!"