, когда я тестирую ниже код с server = smtplib.SMTP('smpt.gmail.com:587')
, он работает нормально.
Но когда я меняю SMTP-сервер на server = smtplib.SMTP('10.10.9.9: 25')
- выдает ошибку.Этот SMTP не требует пароля.
Так чего мне здесь не хватает?
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import pandas as pd
def send_email(user, recipient, subject):
try:
d = {'Col1':[1,2], 'Col2':[3,4]}
df=pd.DataFrame(d)
df_html = df.to_html()
dfPart = MIMEText(df_html,'html')
user = "myEmail@gmail.com"
#pwd = No need for password with this SMTP
subject = "Test subject"
recipients = "some_recipientk@blabla.com"
#Container
msg = MIMEMultipart('alternative')
msg['Subject'] = subject
msg['From'] = user
msg['To'] = ",".join(recipients)
msg.attach(dfPart)
#server = smtplib.SMTP('smpt.gmail.com:587') #this works
server = smtplib.SMTP('10.10.9.9: 25') #this doesn't work
server.starttls()
server.login(user, pwd)
server.sendmail(user, recipients, msg.as_string())
server.close()
print("Mail sent succesfully!")
except Exception as e:
print(str(e))
print("Failed to send email")
send_email(user,"","Test Subject")