用Python群发邮件,自动获取客户列表,自动添加客户昵称和附件

做外贸的同学工作需要, 不可避免的要给国外客户定期发送一些新品推荐或者祝福之类的邮件.
一个一个录入邮件地址,发送邮件,就占用半天时间很麻烦.

基本需求:
1.从指定的客户联系表中取出客户姓名和邮箱地址
2.添加附件
3.每封邮件要单独发送,单独昵称
4.多个邮箱轮流发,每个邮箱不要发送太多邮件,避免被封.
我就用Python写了一个群发程序,实现一个简单的客户群发邮件源码如下,只需要修改成你自己的文件地址,邮箱账号和密码,就可以了,需要的同学拿去用吧

import yagmail
import pandas as pd
def get_email_names():
    infos = pd.read_excel('D:\\BaiduNetdiskWorkspace\\quotation\\早餐机客户0924.xlsx')
    # infos = infos[infos['产品'].isin(['早餐机'])]
    client_names = infos['姓名'].values.tolist()
    client_names.append('Luke')
    email_names = infos['邮箱'].values.tolist()
    email_names.append('15874685@qq.com')
    email_names = dict(zip(client_names,email_names))
    print(email_names)
    return email_names
def send_breakfast_mail(client_name,email_name,yagmail_server):

    yagmail_server = yagmail_server
    email_names = [email_name]
    email_title = ["Re: Quotation for Breakfast-Machine Sales Enquiry"]
    email_content = [f'''Dear {client_name},
                        It was a nice meeting you in our Alibaba store.                                           
                        A few balck color EU plug Version items left in stock.
                        If you need it ,please order soon.
                        Price:17.5USD/set
                        Please kindly find the attachment for the real picture.
                        
                        If you don't need it now,please save our contact information for future.                        
                                           
                        Specifications for your reference as below:
                        Product Name:3 in 1 Breakfast Maker
                        Brand Name:OEM
                        Color:BLack
                        Plug:EU
                        Function:One machine for three purposes( frying, roasting and boiling)
                        coffee pot:450W power 600ml capacity; 
                        Frying pan power:600W; 
                        Oven capacity:9L
                                                
                        Price:17.8USD/set. 
                        Shipping fee:If you have forwarder in China,The shipping fee will cost only $2/set.
                        
                        If you have any special request or questions, pls feel free to let us know. We will try our best to do what we can.
                        
                        If you need any other small kitchen appliances,welcome to contact us.
                        All is factory price!One sample is also wholesale price!

                        Appreciate your early reply!                        
                        ________________________________________
                        Best Regards,
                                              
                        Luke Yan
                                              
                        International Sales Department
                        Hunan Aiwowo Technology Co.,Ltd.
                        Website : https://aiwowo.en.alibaba.com/
                        Email: luke@aiwowocn.com
                        Email: huibf@qq.com
                        Tel/whatsapp/Wechat: + 86 185 0842 9990
                        The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to share any part of this message with any third party, without a written consent of the sender. If you received this message by mistake, please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.
                        ''']
    email_attachment = ["D:\\料理机产品图库\\breakfastmaker\\black.jpg"]
    yagmail_server.send(to=email_names, subject=email_title, contents=email_content, attachments=email_attachment)
    yagmail_server.close()

if __name__ == '__main__':
    email_names = get_email_names()
    count = 0
    	#输入自己的邮箱用户名和密码
    yagmail_servers = [yagmail.SMTP(user="luke@aiwowocn.com", password="password", host="smtp.exmail.qq.com"),
                      yagmail.SMTP(user="user@qq.com", password="password", host="smtp.qq.com")]
                      #无论成败,每个邮箱每天发送40封邮件.
    max_count = len(yagmail_servers)*40
    for client_name,email_name in email_names.items():
        yagmail_server = yagmail_servers[count//40]
        count += 1
        try:
            if 0< count < max_count+1:
                send_breakfast_mail(client_name=client_name,email_name=email_name,yagmail_server=yagmail_server)
                print(f'第{count}封发给{email_name}的邮件发送完毕')
            else:
                break
        except :
            print(f'第{count}封发给{email_name}的邮件发送错误')
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值