2017-05-31 9 views
0

ここからhttps://docs.python.org/2/library/email-examples.htmlのサンプルPythonコードがあります。ここで電子メールを正常に送信できます。pythonのsmtplibを使用して、今後どのように電子メールを送信できますか?

# Import smtplib for the actual sending function 
import smtplib 

# Import the email modules we'll need 
from email.mime.text import MIMEText 

me = "[email protected]" 
you = "[email protected]" 
textfile = 'msg.txt' 

# Open a plain text file for reading. For this example, assume that 
# the text file contains only ASCII characters. 
fp = open(textfile, 'rb') 
# Create a text/plain message 
msg = MIMEText(fp.read()) 
fp.close() 

# me == the sender's email address 
# you == the recipient's email address 
msg['Subject'] = 'The contents of %s' % textfile 
msg['From'] = me 
msg['To'] = you 

# Send the message via our own SMTP server, but don't include the 
# envelope header. 
s = smtplib.SMTP('localhost') 
s.sendmail(me, [you], msg.as_string()) 
s.quit() 

私は2日後にメールを送信するのを延期したいと思います。電子メールの送信を遅らせるsmtplibのパラメータはありますか?私は自分で何かを見つけることができませんでした。

答えて

1

Linuxの場合は、cronジョブを使用できます。

Smtplibは単なるライブラリであり、あなたが指定したプロバイダによって電子メールが送信されます。遅延メッセージの送信をサポートする電子メールプロバイダを見つけることができる場合は、

このスクリプトを実行してtime.sleep(2 * 24 * 60 * 60)を使用することができます。 2日

0

おそらくそうではありません。あなたがこれを行う場合であっても

、正しい番号と5の交換:

import time 
time.sleep(5) # delays for 5 seconds 

ザ・Pythonプログラムは、全体の時間

のために実行されている必要があります。
関連する問題