[英]How can I extract columns of data from a CSV file and define them as x and y variables, then plot them in python using pylab?
[英]How to extract values from columns in CSV using a loop and use them in email body using python?
我正在嘗試將“id”和“desc”的值發送到 B 列中的電子郵件。我使用 for 循環遍歷電子郵件列表並發送電子郵件,但是,我無法附加“id”的值”和“desc”在我的電子郵件中。
另外,我希望“分配給”列填充“id”發送到的電子郵件 ID。
import pandas as pd
import win32com.client
e = pd.read_csv('combo.csv')
emails = e['Emails'].values
ticket_number = e['id'].values
desc_value = e['desc'].values
for i in emails, ticket_number, desc_value:
outlook = win32com.client.Dispatch("Outlook.Application")
message = 'Hello the ticket number {ticket_number} with the Description {desc_value} has been assigned to you.'
mail = outlook.CreateItem(0)
mail.To = i
mail.Subject = 'This is a test'
mail.HTMLBody = message
mail.Send()
有人可以指導我如何 1. 使用這些值發送電子郵件。 2. 發送電子郵件后,在“分配給”列中添加電子郵件。
嘗試這個:
import pandas as pd
import win32com.client
def send_mail(email, ticket_number, desc_value):
outlook = win32com.client.Dispatch("Outlook.Application")
message = f'Hello the ticket number {ticket_number} with the Description {desc_value} has been assigned to you.'
mail = outlook.CreateItem(0)
mail.To = email
mail.Subject = 'This is a test'
mail.HTMLBody = message
mail.Send()
if __name__ == "__main__":
df = pd.read_csv('combo.csv')
df.apply(lambda row: send_mail(row['Emails'], row['id'], row['desc']), axis=1)
或者只是在您的代碼中進行更改:
import pandas as pd
import win32com.client
e = pd.read_csv('combo.csv')
emails = e['Emails'].values
ticket_number = e['id'].values
desc_value = e['desc'].values
for i in range(len(emails)):
outlook = win32com.client.Dispatch("Outlook.Application")
message = f'Hello the ticket number {ticket_number[i]} with the Description {desc_value[i]} has been assigned to you.'
mail = outlook.CreateItem(0)
mail.To = emails[i]
mail.Subject = 'This is a test'
mail.HTMLBody = message
mail.Send()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.