主题行未出现在从python发送的smtp邮件中 [英] Subject line not coming in the smtp mail sent from python

查看:77
本文介绍了主题行未出现在从python发送的smtp邮件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码正在运行并正在发送邮件。
但是 To Subject 不在邮件中。这是我使用的代码片段。

My code is running and sending the mail. But To and Subject are not coming in the mail. Here is a snippet of the code i used. What could be the issue?

代码:

   username = "N@EXAMPLE.com"
   password = "fnEOFINO"


   print("Logged in")

   sender = 'n@example.com'
   receivers = 'T@example.com'
   message = """From: Neeraja Rajiv  <NRajiv@EXAMPLE.com>
   To: T@EXAMPLE.COM 
   Subject: SMTP e-mail test

   Overall
   %d
                                               """%(variable)
   print("Connecting to server")

   server = smtplib.SMTP('SMTP-********.com', 25)
   print("Connected to server")
   server.set_debuglevel (1)
   server.sendmail(sender,receivers,message)         
   print ("Successfully sent email")

在电子邮件中,主题丢失。

In the Email, subject is missing.

任何方法/建议都非常受欢迎。

Any approaches/suggestions are most welcome.

推荐答案

帕拉克·坎宁安(Padraic Cunningham)示例看起来正确。这是另一个示例。也许这可能对您有帮助...

Padraic Cunningham example looks correct. Here is another example. Maybe this might help...

将电子邮件发送到SMTP服务器Python脚本的示例:

Sample Email To SMTP Server Python Script:

import smtplib

import smtplib

try:

host = '?.?.?.?'                                              #The Address To Your SMTP Server...
port = 25

to = 'reciever@someplace.com'                                 #Reciever Of Email...
from_addr = 'sender@someplace.com'                            #Sender Of Email...

subject = '<YOUR SUBJECT HERE>'                               #Subject Of Email...

text_line_1 = 'Body Line 1...\r\n'                            #Body Of Email...
text_line_2 = '\r\n'
text_line_3 = 'Body Line 3...\r\n'
text_line_4 = '\r\n'
text_line_5 = 'Body Line 5...\r\n'

total_message = text_line_1 + text_line_2 + text_line_3 + text_line_4 + text_line_5 

msg = "From: %s\nTo: %s\nSubject: %s\n\n%s" % (from_addr, [to], subject, total_message)

server = smtplib.SMTP(host, port)
server.sendmail(from_addr, to, msg)

print('Successfully Sent Email...')

例外如e:
print('Exception:'+ str(e))

except Exception as e: print('Exception: ' + str(e))

祝你好运...

这篇关于主题行未出现在从python发送的smtp邮件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆