9

だから私はPythonで電子メールを送信するためのチュートリアルに従っています.問題は、Python 3ではなくPython 2用に書かれていることです(これは私が持っているものです)。それで、私が答えを得ようとしているのは、Python 3の電子メールのモジュールは何ですか? 私が取得しようとしている特定のモジュールは次のとおりです。

from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMETex

また、このモジュールに到達するとエラーが発生するような気がします(上記のモジュールでエラーが発生したため、まだ到達していません)

import smtp

スクリプトは次のとおりです。

from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMETex

fromaddr = ("XXXXX@mchsi.com")
toaddr = ("XXXX@mchsi.com")
msg = MIMEMultipart
msg['From'] = fromaddr
msg['To'] =  toaddr
msg['Subject'] = ("test")

body = ("This is a test sending email through python")
msg.attach(MIMEText(body, ('plain')))

import smptlib
server = smptlib.SMPT('mail.mchsi.com, 456')
server.login("XXXXX@mchsi.com", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
text = msg.as_string()
sender.sendmail(fromaddr, toaddr, text)
4

1 に答える 1

12
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

ところで、ここにあなたのコードのいくつかの間違いがあります:

fromaddr = "XXXXX@mchsi.com" # redundant parentheses
toaddr = "XXXX@mchsi.com" # redundant parentheses
msg = MIMEMultipart() # not redundant this time :)
msg['From'] = fromaddr
msg['To'] =  toaddr
msg['Subject'] = "test" # redundant parentheses

body = "This is a test sending email through python" # redundant parentheses
msg.attach(MIMEText(body, 'plain')) # redundant parentheses

import smtplib # SMTP! NOT SMPT!!
server = smtplib.SMTP('mail.mchsi.com', 456) # `port` is an integer
server.login("XXXXX@mchsi.com", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX") # on most SMTP servers you should remove domain name(`@mchsi.com`) here
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text) # it's not `sender`
于 2015-08-10T11:07:23.003 に答える