0

私はこのコードを持っています:

import smtplib
import os 
import time
import sys
import argparse
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText


    class smsGatewaying:


        def login_gmail(self,user,password):
            self.server = smtplib.SMTP("smtp.gmail.com", 587)
            self.server.starttls()

            try:
                gmail_user = args.gmail_user
                gmail_password = args.gmail_password
            except SMTPAuthenticationError:
                print "SMTP authentication went wrong. Most probably the server didn't accept the username/password combination provided."
            finally:
                if gmail_password < '1':
                    print 'Insert a password!'
                    gmail_password = getpass.getpass(prompt="Insert the GMail password: ")
                else:
                    self.server.login(gmail_user, gmail_password)
                    print 'Login successfully.'
                    time.sleep(0.75)
                    x.select_country()


        def select_country(self):
            print 'Insert country: '
            country = raw_input()

            if country == 'Italy' or country == 'italy':

                italian_carriers = ['number@sms.vodafone.it',
                                    '39number@timnet.com']

                select_carriers = raw_input("Select carriers: ")

                if select_carriers == 'Vodafone' or select_carriers == 'vodafone':
                    number = 0
                elif select_carriers == 'TIM' or select_carriers == 'tim' or select_carriers == 'Tim':
                    number = 1
                else:
                    print "L'operatore telefonico selezionato non è disponibile."
                    time.sleep(0.80)
                    x.select_country()



                x.send_message_normal(italian_carriers[number])

            else:
                sys.exit()



        def send_message_normal(self, carriers):
            msg = MIMEMultipart()
            msg['sender'] = raw_input("Insert sender: ")
            msg['telephone'] = input("Insert telephone number: ")
            text = raw_input("Insert text: ")
            msg.attach = (MIMEText(text))

            carriers.replace('number',str(msg['telephone']))

            final = raw_input("Are you sure?[Y/N] ")


            if final == 'y' or final == 'Y':

                self.server.sendmail(msg['sender'],str(msg['telephone']),text) 

            elif final == 'n' or final == 'N':
                exit_ = raw_input("Do you want to exit?[Y/N] ")

                if exit_ == 'Y' or exit_ == 'y':

                    print 'Run main script...'
                    newWorkingDirectory = '../BRES.py'
                    os.path.join(os.path.abspath(sys.path[0]), newWorkingDirectory)
                    os.system('python BRES.py')


    if __name__ == '__main__':
        parser = argparse.ArgumentParser()
        parser.add_argument("gmail_user", type=str)
        parser.add_argument("gmail_password",type=str)

        args = parser.parse_args()


        x = smsGatewaying()
        print 'Welcome to SMS Gatewaying service! Multiple countries and multiple carriers are available.'
        time.sleep(1)
        x.login_gmail(args.gmail_user,args.gmail_password)

番号にメッセージを送信しようとした後、シェルで次のエラーが発生しました。

smtplib.SMTPRecipientsRefused: {'29403983292209': (553, "5.1.2 受信者ドメインが見つかりませんでした。\n5.1.2 のスペルミスをチェックし、スペースやピリオドを入力していないことを確認してください,\n5.1.2 または受信者の電子メール アドレスの後のその他の句読点。a6sm58887940eei.10 - gsmtp")}

私はすべてを試しましたが、解決策はありません:(

4

2 に答える 2

0

次の行を検討してください。

self.server.sendmail(msg['sender'],str(msg['telephone']),text) 

msg['telephone']この時点での価値は何だと思いますか?各パラメータの値を に出力してみてくださいself.server.sendmail()msg[telephone]それが電話番号だと分かると思います。メールアドレスではありません。

あなたが持っているものの代わりに、これらの2行を使用してみてください:

to = carriers.replace('number',str(msg['telephone']))

self.server.sendmail(msg['sender'],to,text) 
于 2013-11-05T16:40:22.543 に答える