# -*- coding: utf-8 -*- import urllib2, urllib, sys,os,re,requests,time API_URL = "https://edm.aiacademy.tw/tools/sendmail/tech2021_aiacademy_tw_send_email.php" s = """

2020 AI Academy 台灣人工智慧年會的與會者,您好:

感謝您報名年會,請您點選以下的連結,獲得您的行前通知:包括年會的相關資訊,以及為了防疫所作的相關措施。

https://docs.google.com/document/d/1lDQeh4gPNnFJyi7Yr3Jkhd9dikFL6FiKg1towkoDkR8/edit

(若點擊連結失效,請手動複製連結,貼於瀏覽器 Safari / Chrome / IE / Edge 中,謝謝!)

期待您的蒞臨,一起來參與這個台灣AI界的年度盛會。

""" #with open('batch_sendmail_for_2days.test.php', 'r') as f: with open('batch_sendmail_for_2days.php', 'r') as f: users = f.read() ary_users = users.split("\n") for i,_ in enumerate(ary_users): if '@' not in _: continue _ = _.split(",") useremail = [_[0]] if len(_)>=2 and '@' in _[1]: useremail += [_[1]] useremail += ['tech2021days@sted.tw'] useremail = ",".join(useremail) post_content = s subj = '2020 AI Academy 台灣人工智慧年會【行前】通知' post_data = {'to' : useremail, 'post_title': subj, 'post_content':post_content, 'sender':'tech2021@aiacademy.tw'} # debug START print '#', useremail # debug END #post_data = urllib.urlencode(post_data) #req = urllib2.Request(API_URL, data=post_data) #res = urllib2.urlopen(req).read() #print res res = requests.post(API_URL, data=post_data) print res.text, subj, useremail time.sleep(1.5)