python smtplib 관련 문제..

ha3k1e의 이미지

python의 smtplib를 이용하여 메일 전송을 자동화 하려고합니다.

현재 같은 도메인,

그러니까 smtplib.SMTP("test@example.com",25)로 접속 했을 때, 도메인이 example.com인 것으로는 잘 보내어지는데

naver.com이나 gmail.com 같은 타 도메인으로는 메일이 전송되지 않습니다.

정확히는 메일을 전송했다고 뜨고, 아무런 에러도 나오지 않는데, 메일이 도착하지 않습니다.

저와 같은 이슈를 해결한 글을 찾지 못하겠네요 ㅠㅠ

혹시 이유가 무엇인지 아시나요..

def send_mail(msg):
    smtplib.SMTP('test@example.com",25)
    smtp.starttls()
    smtp.sendmail(_from, _to, msg.as_string())
    smtp.quit()

참고로 login을 안해도 사용할 수 있도록 웹 메일 시스템이 설정되어있고,

수동으로 보낼때는 다른 도메인으로 전송되기때문에 릴레이 문제도 아닙니다.

익명 사용자의 이미지

Python을 잘 알지는 못하지만, 파이썬 문제라기 보다는

exampl.com의 smtpd 서버 설정이 문제 인거처럼 보이네요

먼저 아래처럼 smtpd가 잘 동작 하는지 테스트 해보시고, 파이썬에서 테스트 해보시는게 좋을 듯 합니다.

telnet exampl.com 25 
 
20 smtp.example.com ESMTP Postfix  
C: HELO relay.example.org  
S: 250 Hello relay.example.org, I am glad to meet you  
C: MAIL FROM:<bob@example.org>  
S: 250 Ok  
C: RCPT TO:<alice@example.com>  
S: 250 Ok  
C: RCPT TO:<theboss@example.com>  
S: 250 Ok  
C: DATA  
S: 354 End data with <CR><LF>.<CR><LF>  
C: From: "Bob Example" <bob@example.org>  
C: To: "Alice Example" <alice@example.com>  
C: Cc: <a href="mailto:theboss@example.com" rel="nofollow">theboss@example.com</a>  
C: Date: Tue, 15 Jan 2008 16:02:43 -0500  
C: Subject: Test message  
C:  
C: Hello Alice.  
C: This is a test message with 5 header fields and 4 lines in the message body.  
C: Your friend,  
C: Bob  
C: .  
S: 250 Ok: queued as 12345  
C: QUIT  
S: 221 Bye  
{The server closes the connection}

출처 : http://blog.saltfactory.net/send-mail-via-smtp-and-python/