2012-04-11 7 views
0

私のサーバーのいずれかでsendmailを使用してエラーレポートを送信しています。私は文字列に追加してこのレポートを作成しています。次にsendmailを使用して電子メールを送信します。ただし、sendmailは文字列のタブを認識しません。私はこれをどのように修正するのだろうと思っていますか?Sendmailがタブを解析していません

def sendMail(data): 
    sendmail_location = "/usr/sbin/sendmail" # sendmail location 
    p = os.popen("%s -t" % sendmail_location, "w") 
    p.write("From: %s\n" % "[email protected]") 
    p.write("To: %s\n" % "[email protected]") 
    p.write("Subject: the subject\n") 
    p.write(data) 
    status = p.close() 
    if status != 0: 
     print "Sendmail exit status", status 

例列は次のようになります

data = "%d\t%s\t%s\n" % (count, message, message2) 
+1

「認識する」とはどういう意味ですか?それは電子メールからそれらを取り除いていますか?あなたが与えたコードが実際にタブを持っていないときは混乱します。データの "文字列の例"ですか? –

+0

はい。私はsendMail(data)を送ります。ここでdataは入力文字列の例です。 – jmnwong

答えて

1

ものが現時点で見方法、その行はヘッダとして扱われています。ヘッダーの後に空白行が必要です。

def sendMail(data): 
    sendmail_location = "/usr/sbin/sendmail" # sendmail location 
    p = os.popen("%s -t" % sendmail_location, "w") 
    p.write("From: %s\n" % "[email protected]") 
    p.write("To: %s\n" % "[email protected]") 
    p.write("Subject: the subject\n") 
    p.write("\n")         # blank line 
    p.write(data) 
    status = p.close() 
    if status != 0: 
     print "Sendmail exit status", status 
+0

それはそうしました。ありがとう。 – jmnwong

関連する問題