def run_job(): date = datetime.now() sub_folder = str(date.hour) s3_folder = '{0}-{1}-{2}/{3}/'.format(str(date.year), str(date.month), str(date.day), sub_folder) email_config = json.load(open('config/email.json')) account = gmail.GMail(email_config['sender_email'], email_config['sender_pass']) hours_to_pull = '24' try: subprocess.check_output(['python', '-m', 'scripts.radian6', '--hours', hours_to_pull, s3_folder]) result = subprocess.check_output(['python', '-m', 'scripts.post_prepper', '{0}'.format(s3_folder)]) email_message = (''' The Radian6 to Salesforce export/import ran with the following results: {0} ''').format(result) msg = gmail.Message('Radian6 to Salesforce results', to=', '.join(email_config['recipients']), text=email_message) account.send(msg) print(result) except subprocess.CalledProcessError as e: #e = sys.exc_info()[0] email_message = (''' An error occurred while processing Radian6 to Salesforce export/import: {0} ''').format(str(e.output)) msg = gmail.Message('ERROR: Radian6 to Salesforce', to=', '.join(email_config['recipients']), text=email_message) account.send(msg) raise
def sendGmail(u, p, t, s, b, a): #u=user,p=pass,t=to_addr,s=subject,b=body,a=attachment client = gmail.GMail(u, p) if a == '': message = gmail.Message(s, to=t, text=b) else: message = gmail.Message(s, to=t, text=b, attachments=[a]) client.send(message) client.close()
def _send_email_passchange(user): registration_uuid = str(uuid.uuid4()) registration_uuid = registration_uuid + str(uuid.uuid4()) ChangePasswordRequest.objects.create(user_pk=user.pk, user_token = registration_uuid) g = gmail.GMail('*****@*****.**', '123456789qQ') msg = gmail.Message('Herdius ICO Password changing', to = user.email, html=html1.replace('myhref', 'http://www.opnplatform.io/development/changepass/' + str(registration_uuid))) g.send(msg)
def send_email(msg_to_send, emailaddr): msg_subject = msg_to_send msg_body = 'link: http://www.wolai66.com/commodity?code=17206586167' gworker = gmail.GMailWorker("[Gmail]", '[password]') msg = gmail.Message(subject=msg_subject, to=emailaddr, text=msg_body) gworker.send(msg) gworker.close() print "send email end"
def dictionaryToMail(self, uid, d): mail = gmail.Message(self.g.inbox(), uid) if d['fetched'] == True: mail.fr = d['from'] mail.subject = d['subject'] mail.body = d['body'] mail.html = d['html'] return mail
def main(): srv = gmail.GMail('Username do Gmail', 'Senha do Gmail') att1 = 'nome do anexo(opcional) ou caminho do anexo' exist = os.path.exists(att1) # verifica se o anexo existe (opcional); if exist == False: #anexo não existe; warning = gmail.Message('Título do e-mail', to='*****@*****.**', text='Texto do e-mail') srv.send(warning) else: #anexo existe; msg = gmail.Message('Título do e-mail', to='*****@*****.**', text='Texto do e-mail', attachments=[att1]) srv.send(msg) delArchive() #procedimento para deletar o anexo(opcional);
def send(self, to, sub, msg): message = gmail.Message(sub, to, html=msg) # check if not connected then connect if not self.sender.is_connected(): self.sender.connect() # send email self.sender.send(message) return True
def send_gmail(subject, body, address, message_mode='text'): must_have_keys = set(['email_username', 'email_password', 'email_from']) conf = get_conf() my_gmail = gmail.GMail(conf.email_username, conf.email_password) if message_mode == 'html': msg = gmail.Message(subject, html=body, to=address, sender=conf.email_from) else: msg = gmail.Message(subject, text=body, to=address, sender=conf.email_from) try: my_gmail.send(msg) except gmail.gmail.SMTPAuthenticationError as e: print e.smtp_error return False return True
def send_mail(body, attachment=''): address = '*****@*****.**' sender_address = '*****@*****.**' SENDER_NAME = '渡邊 由彦' username = '******' password = '' # Need the real password here client = gmail.GMail(username, password) finished = datetime.datetime.now() finished_f = finished.strftime("%Y/%m/%d %H:%M:%S") if attachment == '': message = gmail.Message(u'BSニュースTweet ' + finished_f, to=address, text=body) else: message = gmail.Message(u'BSニュースTweet ' + finished_f, to=address, text=body, attachments=[attachment]) client.send(message) client.close() return
def sendImageByGmail(subject, body, image): if (settings.SEND_EMAIL is not True): return user = settings.GMAIL_USER password = settings.GMAIL_PASS client = gmail.GMail(user, password) to = settings.GMAIL_TO subject = "[facesesame] " + subject if image == '': message = gmail.Message(subject, to=to, text=body) else: attachment = MIMEImage(image, 'jpeg', filename="file.jpg") attachment.add_header('Content-Disposition', "attachment; filename=file.jpg") message = gmail.Message(subject, to=to, text=body, attachments=[attachment]) client.send(message) client.close()
def main(): #アカウント名 username = '******' + "@gmail.com" #パスワード password = '******' client = gmail.GMail(username,password) #メッセージ内容 message = gmail.Message(u'サブジェクト : HellWorld', to = username , text = u'ボディ : これはテストケース注意されたし!!' ) client.send(message) client.close() return 0
def do_send(program): client = gmail.GMail(user_name, password) message = gmail.Message(u'サブジェクト:こんにちは世界', to=user_name, text=u'ボディ:これはテストメッセージです') try: # client.send(message) print('test') except Exception as e: raise e client.close() return True
def fetchByUID(self, uid, update_db=True): if self.g.logged_in == False: return None if uid in self.db and self.db[uid]['fetched'] == True: return self.dictionaryToMail(uid, self.db[uid]) mail = gmail.Message(self.g.inbox(), uid) try: mail.fetch() if update_db == True: self.insertIntoDB([mail], force=False) return mail except Exception as e: print("Can't update db:") print(e) return None
def send_email(self, recipient, subject, content): """ Send an email to recipient. Returns empty action result with status. :param recipient: recipient email address (str) :param subject: subject of an email (str) :param content: content of an email (str) :return: """ assert (isinstance(recipient, str) and isinstance(subject, str) and isinstance(content, str)) #TODO:add some regex validator for [to] email address print("Calling send_email with params [subject = {}, recipient = {}, content = {}]".\ format(subject, recipient, content)) new_message = gmail.Message(subject, to=recipient, text=content) status_code = self._api.send(new_message) status = "success" if status_code is None else "fail" print("Email sending finished with status = {}".format(status))
def send_gmain(): msgs = loadProperties() # Gmailアカウント情報 sendUsername = msgs['from'] #'*****@*****.**' sendUserPassword = msgs['mailpass'] #'from_user_password' # メール送信パラメータ subject = msgs['subject'] toAddr = msgs['to'] #'*****@*****.**' cc = msgs['cc'] #'*****@*****.**' body = loadBody() #print(msgs) # メールサーバに接続して、ログインとメール送信 try: print('メール送信開始') # Gmailへのログインとメール送信 client = gmail.GMail(sendUsername, sendUserPassword) message = gmail.Message(subject=subject, to=toAddr, cc=cc, text=body) client.send(message) client.close() print('メール送信完了!') except Exception as e: # メール送信エラー時の対処 try: client.close() except: print('メール送信エラーです。') return -1 now_date = str(datetime.datetime.now()) writeHistory('[ERROR] : ' + now_date + ' : メール送信に失敗しました\n') writeHistory(' ' + str(e) + '\n') print('メール送信エラーです。') return -1 return 0
name, price, local, post_time, link) # Read in uname/pword here so that it's not in memory creds_file = open('arcf/.creds_file.txt', 'r') uname = creds_file.readline().strip() pword = creds_file.readline().strip() creds_file.close() gm = gmail.GMail(uname, pword) uname = None pword = None gm.connect() try: msg = gmail.Message( 'New {} Found on Craigslist'.format( thing.strip().upper()), to='*****@*****.**', text=body) gm.send(msg) postings.append(pid) # Update our list existing_item_list_file = open("list_file.txt", 'w') for p in postings: existing_item_list_file.write(str(p) + '\n') existing_item_list_file.close() except: logging.debug( "Something went wrong for posting {}".format(pid)) pass
import gmail as gm password = '******' mailFrom = '*****@*****.**' message = 'mail cisco meraki' auth = gm.Gmail(mailFrom, password) msg = gm.Message(subject, to=mailTo, text=message) auth.send(msg)
try: print('メール送信開始') # ユーザ名とパスワードの入力 print('MailAccount: ', end=' ') sendUsername = input() sendUserPassword = getpass.getpass() # 受信者アドレスの入力 print('宛先アドレス: ', end=' ') toAddr = input() # 件名と本文の入力 print('件名: ', end=' ') subject = input() print('メール本文: ', end=' ') body = input() # Gmailへのログインとメール送信 client = gmail.GMail(sendUsername, sendUserPassword) message = gmail.Message(subject=subject, to=toAddr, text=body) client.send(message) client.close() print('メール送信完了!') except: # メール送信エラー時の対処 try: client.close() except: pass print('メール送信エラーです。')
def _send_email(user): registration_uuid = uuid.uuid4() RegistrationRequest.objects.create(user_pk=user.pk, user_registration_uuid = registration_uuid) g = gmail.GMail('*****@*****.**', '123456789qQ') msg = gmail.Message('Herdius ICO Registration', to = user.email, html=html.replace('myhref', 'http://www.opnplatform.io/development/activate/' + str(registration_uuid))) g.send(msg)
# coding: utf-8 import gmail # Login to Gmail settings GMAIL_USER = '******' GMAIL_PASS = '******' # Mail parameter TOADDR = '(slackbot)@(your workspace).slack.com)' subject = '日本語' # Japanese body = 'メッセージ\n改行も' # Message, and new line message = gmail.Message(subject, to=TOADDR, text=body) # send mail client = gmail.GMail(GMAIL_USER, GMAIL_PASS) client.send(message) client.close()