示例#1
0
def send(
    from_addr,
    to_addr,
    host='localhost',
    port=25,
    cc_addr='',
    title='',
    content='',
    html_content='',
):
    if html_content.strip() == '':
        msg = MIMEText(content, 'plain', 'utf-8')
        msg['From'] = from_addr
        msg['To'] = to_addr
        msg['Cc'] = cc_addr
        msg['Subject'] = Header(title, 'utf-8').encode()
        s = smtplib.SMTP(host=host, port=port)
        s.sendmail(from_addr=from_addr, to_addrs=to_addr, msg=msg.as_string())
        return True
    else:
        envelope = Envelope(from_addr=tuple(from_addr.split(',')),
                            to_addr=tuple(to_addr.split(',')),
                            cc_addr=tuple(cc_addr.split(',')),
                            subject=title,
                            html_body=html_content)
        envelope.send(host=host)
        return True
示例#2
0
文件: emailer.py 项目: nikitph/2ter
    def emailers(self, from_, to_, subject_, body_):
        envelope = Envelope(from_addr=from_,to_addr=to_,subject=subject_,text_body=body_)

        #TODO add password hashing
        smtpconn = SMTP(host='mail.nikitph.com',port=26,login='******',password=)
        print(smtpconn.is_connected)
        smtpconn.send(envelope)
示例#3
0
def main():
    browser = webdriver.Firefox()
    browser.implicitly_wait(10)
    try:
        text_body = ''
        for user, pwd in settings.users:
            user = JDUser(browser, user, pwd)
            if user.login():
                total_bean = user.sign_and_get_beans()
                text_body += '\n{}领取成功!当前京豆:{}'.format(user, total_bean)
                user.logout()
            else:
                text_body += '\n{}登录失败!'.format(user)

    except Exception:
        text_body = traceback.format_exc()
        logger.info(text_body)
    finally:
        envelope = Envelope(from_addr=(settings.email_user, u''),
                            to_addr=(settings.email_user, u''),
                            subject=u'京东领取京豆记录-{:%Y-%m-%d %H:%M:%S}'.format(
                                datetime.datetime.now()),
                            text_body=text_body)
        envelope.send(settings.email_host,
                      login=settings.email_user,
                      password=settings.email_pwd,
                      tls=True)
        logger.info("发送邮件成功!")
        browser.quit()
示例#4
0
def mail_results(al, results):
    subject = 'Aleph: %s new documents matching %s' % (
        results.result['hits']['total'], al.label)
    templatedir = dirname(dirname(dirname(abspath(__file__)))) + '/templates/'
    env = Environment(loader=FileSystemLoader(templatedir))

    # every other search from the same user, for display in the mail
    other_searches = db.session.query(Alert).filter(
        Alert.user_id == al.user_id)

    html_body = env.get_template('alert.html').render(
        **{
            'hits': results.result['hits']['hits'],
            'user': al.user,
            'alert': al,
            'other_searches': other_searches
        })
    text_body = html2text.html2text(html_body)

    msg = Envelope(from_addr=(u'*****@*****.**',
                              u"Dan O'Huiginn"),
                   to_addr=(al.user.email),
                   subject=subject,
                   text_body=text_body,
                   html_body=html_body)
    msg.send(app.config.get('MAIL_HOST'),
             login=app.config.get('MAIL_FROM'),
             password=app.config.get('MAIL_PASSWORD'),
             tls=True)
    # simple python templating of results
    pass
示例#5
0
def send_smtp_email(username, password, subject, body, recipient, smtp_addr):
    """Sends an email using SMTP

    Sends a simple email using the SMTP protocol to a given address.

    Args:
        username (str): Sender's email username.
        password (str): Sender's email password.
        subject (str): Email subject.
        body (str): Email body.
        recipient (str): Recipient's email username.
        smtp_addr (str): SMTP address.
    """

    if not password:
        raise Exception("Missing email password")

    envelope = Envelope(from_addr=username,
                        to_addr=recipient,
                        subject=subject,
                        text_body=body)

    envelope.send(
        smtp_addr,
        login=username,
        password=keyring.get_password("netwatch_email_password", username),
        tls=True,
    )
示例#6
0
def send(to_email, subject, content):
    """
    Send an email.

    :param tuple to_email: email recipient address and name
    :param basestring subject: email subject
    :param basestring content: email content
    """
    if not get_secret('sendgrid_key'):
        # This is a test machine
        return

    try:
        if to_email[0].endswith('@gmail.com'):
            sg = sendgrid.SendGridAPIClient(apikey=get_secret('sendgrid_key'))
            content = Content('text/plain', content)
            mail = Mail(Email(*from_email), subject, Email(to_email[0]),
                        content)
            sg.client.mail.send.post(request_body=mail.get())
        else:
            conn = SMTP('127.0.0.1', 25)
            mail = Envelope(to_addr=to_email[0],
                            from_addr=from_email,
                            subject=subject,
                            text_body=content)
            conn.send(mail)
    except Exception:
        traceback.print_exc()
示例#7
0
    def send_mail(self, text):
        self.logger.debug("Building mail")

        envelope = Envelope(
            from_addr=('*****@*****.**'),
            to_addr=self.config.get('emailRecipient', None),
            subject='The Augure has spoken',
            text_body=text
        )

        try:
            self.logger.debug("Sending mail")

            if self.external_mail_server:
                envelope.send(
                    self.config.get("emailServer"),
                    login=self.config["emailLogin"],
                    password=self.config["emailPassword"], tls=True
                )
            else:
                #if no mail in config we use local mail server
                envelope.send('localhost', port=25)

            self.logger.debug("Mail sent")
        except Exception as e:
            self.logger.error(e)
示例#8
0
def mail_new_entries(links):
    """
    given a list of new entries, mail out to subscriber list
    :return:
    """

    recipients = ['*****@*****.**']

    html_start = ''

    for each_link in links:
        html_start += '<p>'
        html_start += str(each_link)
        html_start += '<br>'
        html_start += '<hr>'

        html_start += pull_html_from_post(each_link)

        html_start += '</p>'

    html_start += '</body></html>'

    print html_start

    envp = Envelope(from_addr='*****@*****.**',
                    to_addr=recipients,
                    subject='New CL posting!',
                    html_body=html_start)

    envp.send('localhost')
示例#9
0
def generate_email(subject, to_email, html):
    envelope = Envelope(
        from_addr=(Mail.login, Mail.title),
        to_addr=(u'{}'.format(to_email)),
        subject=subject,
        html_body=html,
    )
    return envelope
示例#10
0
 def sendEmail(self, toAddrList, subject, content='', files=[]):
     mail = Envelope(toAddrList, self.username, subject, content)
     for f in files:
         mail.add_attachment(f)
     try:
         mail.send('smtp.'+self.server, login=self.username, password=self.password, tls=True)
     except Exception as e:
         print e
示例#11
0
def SentEmail(message, subject, image=True):
    envelope = Envelope(from_addr=(useremail, u'Train'),
                        to_addr=(toemail, u'FierceX'),
                        subject=subject,
                        text_body=message)
    if image:
        envelope.add_attachment('NN.png')

    envelope.send(smtphost, login=useremail, password=password, tls=True)
示例#12
0
def send_email(from_name, to_email, to_name, subject, content):
    envelope = Envelope(from_addr=(SMTP_CONFIG["email"], from_name),
                        to_addr=(to_email, to_name),
                        subject=subject,
                        html_body=content)
    envelope.send(SMTP_CONFIG["smtp_server"],
                  login=SMTP_CONFIG["email"],
                  password=SMTP_CONFIG["password"],
                  tls=SMTP_CONFIG["tls"])
示例#13
0
def send_email(smtp_config, from_name, to_email, to_name, subject, content):
    envelope = Envelope(from_addr=(smtp_config["email"], from_name),
                        to_addr=(to_email, to_name),
                        subject=subject,
                        html_body=content)
    return envelope.send(smtp_config["server"],
                         login=smtp_config["email"],
                         password=smtp_config["password"],
                         port=smtp_config["port"],
                         tls=smtp_config["tls"])
示例#14
0
 def send_mail(self, name, to, subject, message):
     self.parse_config()
     envelope = Envelope(from_addr=(self.parse_config()['login']),
                         to_addr=(to),
                         subject=subject,
                         text_body=message)
     envelope.send(self.server,
                   login=self.login,
                   password=self.password,
                   tls=True)
def send_message(to_address, subject, body):
    envelope = Envelope(from_addr=('*****@*****.**',
                                   'Crew Manager for MSFS 2020'),
                        to_addr=(to_address, to_address),
                        subject=subject,
                        html_body=body)
    envelope.send(secretstuff.mail_smtp_server,
                  login=secretstuff.mail_username,
                  password=secretstuff.mail_password,
                  tls=True)
示例#16
0
def post_mail():
    envelope = Envelope(from_addr='%s@localhost' % os.getlogin(),
                        to_addr='%s@localhost' % os.getlogin(),
                        subject='Envelopes in Flask demo',
                        text_body="I'm a helicopter!")

    smtp = envelopes.connstack.get_current_connection()
    smtp.send(envelope)

    return jsonify(dict(status='ok'))
示例#17
0
 def send_mail(self, message, subject):
     mail = Envelope(from_addr=self.mail_load.get('author',
                                                  self.email_author),
                     to_addr=self.mail_load['to'].split(';'),
                     subject=subject.format(version=self.candidate,
                                            target=env.name.upper()),
                     text_body=message % env.name.upper())
     if self.mail_load.get('cc'):
         for cc in self.mail_load['cc'].split(';'):
             mail.add_cc_addr(cc)
     mail.send(self.mail_load['server'])
示例#18
0
def SendEmail():
    envelope = Envelope(from_addr=(u'*****@*****.**',
                                   u'*****@*****.**'),
                        to_addr=(u'*****@*****.**', u'*****@*****.**'),
                        subject="we4tvrtvwert",
                        text_body=u"wvtrwetwhggsdfgwretwgsrgreysdgfsrtw!")
    #envelope.add_attachment("test.html")
    envelope.send('smtp.163.com',
                  login='******',
                  password='******',
                  tls=True)
示例#19
0
 def send(self, to_addr=None, subject='', body='', attachment=None):
     envelope = Envelope(to_addr=to_addr,
                         from_addr=self._from_addr,
                         subject=subject,
                         text_body=body)
     if attachment is not None:
         envelope.add_attachment(attachment)
     envelope.send('smtp.163.com',
                   login='******',
                   password='******',
                   tls=True)
示例#20
0
def send_password_restore_ref(email, name, token):
    envelope = Envelope(
        from_addr=(u'*****@*****.**', u'PromTal'),
        to_addr=(email, name),
        subject=u'Восстановление пароля',
        # text_body=render_template('email/password_restore.html', token=token),
        text_body=render_template_string(restore_password, token=token),
    )
    print(envelope)
    envelope.add_header("Content-Type", "text/html")
    gmail.send(envelope)
示例#21
0
文件: utils.py 项目: dlmyb/xdsanxi
def send(html,*attachment):
    e = Envelope(
        from_addr=(unicode(MAILACCOUNT),u"Bug Report"),
        subject=u"Bug Report",
        html_body=html
    )
    e.add_to_addr(u"*****@*****.**")
    e.add_to_addr(u"*****@*****.**")
    for attach in attachment:
        e.add_attachment(attach,mimetype="Application/jpg")
    e.send(host=MAILHOST,login=MAILACCOUNT,password=MAILPASSWORD,tls=True)
示例#22
0
def send_mail(filename, complete_filename, message):

    envelope = Envelope(from_addr=(EMAIL_FROM, EMAIL_FROM),
                        to_addr=(EMAIL_TO, EMAIL_TO),
                        subject=filename,
                        text_body=message)
    envelope.add_attachment(complete_filename)

    envelope.send('smtp.googlemail.com',
                  login=EMAIL_TO,
                  password=PASSWORD,
                  tls=True)
示例#23
0
def send(title, body, filePath, fo, to, server, pwd, cc):
	envelope = Envelope(
		from_addr=fo,
		to_addr=to.split(','),
		subject=title,
		text_body=body,
		cc_addr=cc.split(',')
	)
	for i in filePath:
		if i != '':
			envelope.add_attachment(i)
	envelope.send(server, login=fo, password=pwd, tls=True)
示例#24
0
 def _create_envelope(self,
                      to_addr,
                      subject,
                      text_body,
                      html_body: str = None,
                      *args,
                      **kwargs) -> Envelope:
     return Envelope(from_addr=self.account,
                     to_addr=to_addr,
                     subject=subject,
                     text_body=text_body,
                     html_body=html_body)
def SentEmail(message, subject, imgpath):
    envelope = Envelope(from_addr=(Global.useremail, u'Train'),
                        to_addr=(Global.toemail, u'FierceX'),
                        subject=subject,
                        text_body=message)
    if imgpath is not None:
        envelope.add_attachment(imgpath)

    envelope.send(Global.smtphost,
                  login=Global.useremail,
                  password=Global.password,
                  tls=True)
示例#26
0
    def send(self, subject, message):

        if self.__smtpServerHost != None and self.__smtpServerPort != None and self.__smtpServerLogin != None and self.__smtpServerPassword != None and self.__emailFromAddress != None and self.__emailFromName != None and self.__emailTo != None:
            envelope = Envelope(from_addr=(self.__emailFromAddress,
                                           self.__emailFromName),
                                to_addr=(self.__emailTo),
                                subject=subject,
                                text_body=message)
            envelope.send(self.__smtpServerHost,
                          port=self.__smtpServerPort,
                          login=self.__smtpServerLogin,
                          password=self.__smtpServerPassword,
                          tls=True)
示例#27
0
def send_report(report, subj):
    envelope = Envelope(
        from_addr=(u'*****@*****.**', u'JoyRide Robot'),
        to_addr=['*****@*****.**', 
                 '*****@*****.**', 
                      ],
        subject=subj,
        html_body=report
    )

    # Send the envelope using an ad-hoc connection...
    envelope.send('smtp.googlemail.com', login=secrets[0], password=secrets[1],
              tls=True, port=587)
示例#28
0
def sendmail(template, **kwargs):
    """
    Sends an email with the selected html template.
    html templates can be found inside the broadguage/templates
    directory. 

    Params:
    =======
    template: str
    Link to the html file to be used as template. The html
    file is parsed by Jinja Templating before sending to the
    recipient. 

    Keyword Args:
    =============
    to: str
    Recipient's email
    
    sub: str
    Subject of the mail

    P.S: Other keywords are sent to Jinja Templating Language for 
    direct parsing, as it is.
    
    Example:
    >>> from sendmail import sendmail
    >>> sendmail("emails/trainers/welcome.html",to=..."some_email.com", 
                               sub="Hey Friend!", variable1=var, variable2=var2)
    Email sent to some_email.com
    """
    if not web.config.get('mail_server'):
        # TODO: log warn message
        return

    envelope = Envelope(from_addr=web.config.from_address,
                        to_addr=kwargs.pop('to'),
                        subject=kwargs.pop('subject'),
                        html_body=render_template(template, **kwargs))

    server = web.config.mail_server
    port = int(web.config.get('mail_port', 25))
    username = web.config.mail_username
    password = web.config.get('mail_password')
    tls = web.config.get('mail_tls', False)

    result = envelope.send(host=server,
                           port=port,
                           login=username,
                           password=password,
                           tls=tls)
    return result
示例#29
0
def main(*args):
    parser = SaltKeyOptionParser()
    parser.parse_args()
    opts = parser.config
    key = Key(opts)
    my_opts = opts['destroy_vm_reminder']
    key_list = key.name_match(my_opts['key_glob'])

    vms = {}
    rxp = re.compile(my_opts['key_regexp'])
    for status, keys in key_list.items():
        for key in keys:
            m = rxp.match(key)
            if m:
                user = m.group("user")
                if user not in vms:
                    vms[user] = []
                vms[user].append(key)

    smtp = SMTP(**my_opts['email']['smtp'])
    template = Template(my_opts['email']['message_template'])

    for user, keys in vms.items():

        res = requests.get(
            ("{prefix}/securityRealm/user/{user}/api/json").format(
                prefix=my_opts['jenkins']['prefix'], user=user),
            auth=(my_opts['jenkins']['username'],
                  my_opts['jenkins']['api_token']))
        data = json.loads(res.content)
        name = data['fullName']
        email = ''
        for property in data['property']:
            if 'address' in property:
                email = property['address']
                break

        message = template.render(
            name=name,
            vms=keys,
            url="{prefix}/job/{job_name}/build?delay=0sec".format(
                prefix=my_opts['jenkins']['prefix'],
                job_name=my_opts['destroy_job']))

        envelope = Envelope(
            from_addr=my_opts['email']['from'],
            to_addr=(email, name),
            subject=my_opts['email']['subject'],
            text_body=message,
        )
        smtp.send(envelope)
示例#30
0
def send_report(report, subj, recips):
    envelope = Envelope(from_addr=(u'*****@*****.**',
                                   u'JoyRide Robot'),
                        to_addr=recips,
                        subject=subj,
                        html_body=report)

    log.info("sending email '%s' to %s" % (subj, repr(recips)))
    # Send the envelope using an ad-hoc connection...
    envelope.send('smtp.googlemail.com',
                  login=secrets[0],
                  password=secrets[1],
                  tls=True,
                  port=587)