我想代表另一个人自动执行一些电子邮件发送任务 . 我在本地机器上绕过交换机发送凭证时遇到了困难 . 这是我的脚本:

import os
import sys

# Recipient mail - 1 mail
param_in= sys.argv[1]
file_in = sys.argv[2]
fixed_param = param_in.split()
fixed_file_in = file_in.split()

def send_mail(send_from: str, subject: str, text: str, send_to: list, send_cc: list, send_bcc: list, files= None, report="yes"):

# Reporting Funcs
def mail_report_beg():
    print("Sender:        " + str(send_from))
    print("Recipients:    " + str(send_to))
    print("Cc Recipients: " + str(send_cc))
    print("Bcc Recipients: " + str(send_bcc))
    print("Attached files: " + str(files))
    print("Sending....")

def mail_report_end():
    print("Mail sent succesfully")

# Required libraries / modules
try:
    import smtplib
    from email.mime.text import MIMEText
    from email.mime.multipart import MIMEMultipart
    from email.mime.application import MIMEApplication
    from email.mime.base import MIMEBase
    from email import encoders
    from os.path import basename
except:
    return ("Failed to load necessary modules", 1)

# Deprecated calls
#from email.MIMEBase import MIMEBase
#from email.MIMEMultipart import MIMEMultipart

if report=="yes":
    mail_report_beg()


# Fall back to default address if no send_to is empty 
send_to= default_address if not send_to else send_to

# Instantiate new MIMEMultipart object
msg = MIMEMultipart()

# Assign Basic Parameters
msg['From'] = send_from
msg['To'] = ', '.join(send_to)  
msg['Subject'] = subject
msg['Cc'] = ', '.join(send_cc)
msg['Bcc'] = ', '.join(send_bcc)

# Assign Body
msg.attach(MIMEText(text))

# Iterate over files and attach
for f in files or []:
    with open(f, "rb") as fil: 
        ext = f.split('.')[-1:]
        attachedfile = MIMEApplication(fil.read(), _subtype = ext)
        attachedfile.add_header(
            'content-disposition', 'attachment', filename=basename(f) )
    msg.attach(attachedfile)

# Send Email
# Server connection info
smtp = smtplib.SMTP(host, port)
#smtp = smtplib.SMTP(host="xxxxxxx", port= 587)     
smtp.starttls()
smtp.login(username,password)
smtp.sendmail(send_from, send_to, msg.as_string())
smtp.close()


if report=="yes":
    mail_report_end()


host="host@host.host" 
port= 587    
username = 'user'
password = 'pass'

default_address = 'defaddress@def.def'


subject_in = 'subjin '
msg2 = """

xxxxxxx

"""

send_mail(
send_from= default_address,
subject=subject_in,
text=msg2,
send_to= fixed_param,
send_cc= ['xxxxx.com.gr', 'xxxx.com.gr'] ,
send_bcc= ['xxxx.com.gr'] ,
files= fixed_file_in
)

我希望能够使用其他用户的凭据发送,从本地计算机运行更可取 . 这可以在运行时以某种方式实现自动化吗?如果是这样,需要启用哪种设置?有没有可以提供相同功能的python库?

提前致谢 .