Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: 'Series' object has no attribute 'split' error in sending emails

How can I solve the below error. The message is as below in splitting the Test emails with a semi-colon? Ideally I should send emails from Sendfrom corresponding emails in Test.

test

SENDFROM        Test 
[email protected]  [email protected];[email protected];[email protected]
[email protected]     [email protected];[email protected];[email protected]
AttributeError: 'Series' object has no attribute 'split'

My code is below:

import smtplib, ssl
from email.message import EmailMessage
import getpass
email_pass = getpass.getpass() #Office 365 password 
# email_pass = input() #Office 365 password 
context=ssl.create_default_context()
for idx, row in test.iterrows():
    
    emails = test['Test']
    sender_list  = test["SENDFROM"]
    
    smtp_ssl_host = 'smtp.office365.com'
    smtp_ssl_port = 587
    email_login = "[email protected]"
    email_from = sender_list
    email_to = emails
    msg2 = MIMEMultipart()
    msg2['Subject'] = "xxx"
    msg2['From'] = sender_list

    msg2['To'] = ", ".join(email_to.split(";"))
    msg2['X-Priority'] = '2'

    text = ("xxxx")
        
    msg2.attach(MIMEText(text))
    s2 = smtplib.SMTP(smtp_ssl_host, smtp_ssl_port)
    s2.starttls(context=context)
    s2.login(email_login, email_pass) 

      
    s2.send_message(msg2)
        
    s2.quit()        
like image 653
Hummer Avatar asked Aug 26 '26 16:08

Hummer


1 Answers

Let's try str.split and str.join:

import pandas as pd

df = pd.DataFrame({'SENDFROM': {0: '[email protected]', 1: '[email protected]'},
                   'Test': {0: '[email protected];[email protected];[email protected]',
                            1: '[email protected];[email protected];[email protected]'}})

# Use str.split and str.join and astype
df['Test'] = df['Test'].str.split(';').str.join(',')

print(df.to_string())

Output:

       SENDFROM                                        Test
0  [email protected]  [email protected],[email protected],[email protected]
1    [email protected]       [email protected],[email protected],[email protected]
like image 169
Henry Ecker Avatar answered Aug 29 '26 07:08

Henry Ecker