2017-08-14 21 views
4

python sendmailで電子メールを送信しようとするとエラーが発生します。Python - 電子メールの送信中にエラー(リレーアクセスが拒否されました)

Traceback (most recent call last): 
    File "./mail.py", line 47, in <module> 
    s.sendmail(me, you, msg.as_string()) 
    File "/usr/lib/python2.7/smtplib.py", line 747, in sendmail 
    raise SMTPRecipientsRefused(senderrs) 
smtplib.SMTPRecipientsRefused: {'[email protected]': (454, '4.7.1 <[email protected]>: Relay access denied')} 

が、私は本当にこれがで働いていない理由を知りません。私はこのメールを送信すると、私はこのエラーを持っている

#! /usr/bin/python 

import smtplib 

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

# me == my email address 
# you == recipient's email address 
me = "[email protected]" 
you = "[email protected]" 

# Create message container - the correct MIME type is multipart/alternative. 
msg = MIMEMultipart('alternative') 
msg['Subject'] = "Link" 
msg['From'] = me 
msg['To'] = you 

# Create the body of the message (a plain-text and an HTML version). 
text = "Hi!\nHow are you?\nHere is the link you wanted:\nhttp://www.python.org" 
html = """\ 
<html> 
    <head></head> 
    <body> 
    <p>Hi!<br> 
     How are you?<br> 
     Here is the <a href="[http://www.python.org">link</a]http://www.python.org">link</a> you wanted. 
    </p> 
    </body> 
</html> 
""" 

# Record the MIME types of both parts - text/plain and text/html. 
part1 = MIMEText(text, 'plain') 
part2 = MIMEText(html, 'html') 

# Attach parts into message container. 
# According to RFC 2046, the last part of a multipart message, in this case 
# the HTML message, is best and preferred. 
msg.attach(part1) 
msg.attach(part2) 

# Send the message via local SMTP server. 
s = smtplib.SMTP('localhost') 
# sendmail function takes 3 arguments: sender's address, recipient's address 
# and message to send - here it is sent as one string. 
s.sendmail(me, you, msg.as_string()) 
s.quit() 

(パドールオブジェ):ここに私のpythonのコードですテスト環境で作業しているため理解してもらえますか?

+0

可能性がありますがGmailのを経由してメールを送信しようとしていますか?あなたは実際に 'local' SMTPサーバーを持っていますか?この回答を見る - https://stackoverflow.com/questions/10147455/how-to-send-an-email-with-gmail-as-provider-using-python – droravr

+0

@droravrいいえ、送信できるようにしたいGmailや他のユーザーにメールを送信する – dmx

+0

電子メールを送信するにはSMTPサーバーが必要です。アカウントがある場合はGmailを使用するか、同じ性質のものを使用します。 – droravr

答えて

0

多分もっと情報が必要です。このエラーは、おそらくドメイン構成によって発生します。

  • あなたのドメインはTESTとPRODで同じですか?
  • TEST対PRODに送信メールを処理内容に応じて、それはアクセス許可の問題
+0

通常それは同一です。 – dmx

関連する問題