示例#1
1
文件: email.py 项目: maoy/mosaic
def send_email(fromAddr, passwd, toAddr, subject, body):
    server = SMTP('smtp.gmail.com',587)
    server.set_debuglevel(0)
    server.ehlo(fromAddr)
    server.starttls()
    server.ehlo(fromAddr)
    server.login(fromAddr,passwd)
    msg = MIMEText(body)
    msg['Subject'] = subject
    msg['From'] = fromAddr
    msg['To'] = toAddr
    server.sendmail(fromAddr,toAddr,msg.as_string() )
    server.quit()
示例#2
0
def mail(content):
    ret = True
    try:

        # msg = MIMEText('填写邮件内容', 'plain', 'utf-8')
        # msg = MIMEText(base64.b64encode(open('C:\Users\dell、\Downloads\\test.txt', 'rb').read()), 'plain', 'utf-8')
        # msg = MIMEText(base64.b64encode(open(content).read()), 'plain', 'utf-8')
        msg = MIMEText(open(content).read(), 'plain', 'utf-8')
        msg = M
        msg['From'] = formataddr(["FromRunoob",
                                  my_sender])  # 括号里的对应发件人邮箱昵称、发件人邮箱账号
        msg['To'] = formataddr(["FK", my_user])  # 括号里的对应收件人邮箱昵称、收件人邮箱账号
        msg['Subject'] = "菜鸟教程发送邮件测试"  # 邮件的主题,也可以说是标题

        server = smtplib.SMTP("smtp.163.com", 25)  # 发件人邮箱中的SMTP服务器,端口是25
        server.login(my_sender, my_pass)  # 括号中对应的是发件人邮箱账号、邮箱密码

        server.sendmail(my_sender, [
            my_user,
        ], msg.as_string())  # 括号中对应的是发件人邮箱账号、收件人邮箱账号、发送邮件
        server.quit()  # 关闭连接
    except Exception:  # 如果 try 中的语句没有执行,则会执行下面的 ret=False
        ret = False
        print "失败"
    return ret
    def send(self, sendto, subject, message):
        if isinstance(sendto, basestring):
            sendto = [sendto]

        for to in sendto:
            msg = MIMEText(message, "plain")
            msg["Subject"] = subject
            msg["To"] = to
            msg["From"] = self.sender

            if not self.debug:
                try:
                    self.smtp.sendmail(self.sender, [to], msg.as_string())
                except:
                    pass
            else:
                print msg.as_string()
示例#4
0
def sendmail(user, msg):
    #TODO: put these details in settings.py
    email_addr = get_user_email(user)

    msg = MIMEText(msg)
    msg['Subject'] = 'Pleiades Cluster Notification'
    msg['From'] = 'Pleiades Cluster<*****@*****.**>'
    msg['To'] = email_addr

    s = SMTP('student.up.ac.za', 25, 'Pleiades')
    s.sendmail('*****@*****.**', [email_addr], msg.as_string())
    s.quit()
示例#5
0
    def alarm(self, *args, **kwargs):
        if not super(self.__class__, self).alarm(**kwargs):
            return False

        self._connect()       
        for msg_to in self.self.opts["msg_to"]:
            msg = MIMEText(self.msg_tmpl.safe_substitute(kwargs))
            msg['Subject'] = self.msg_tmpl_subj.safe_substitute(self.opts)
            msg['From'] = self.opts["msg_from"]
            msg['To'] = msg_to
            self.server.sendmail(self.opts["msg_from"], [msg_to], msg.as_string())
        self._close()

        return True
示例#6
0
文件: sendmsg.py 项目: smaplee/maple
def sendmail(content):
    msg = MIMEText(content,_subtype='html',_charset='utf-8')
    msg['Subject'] = '{time} 项目发布'.format(time=time.strftime('%Y-%m-%d %H:%M:%S'))
    msg['From'] = ("%s<"+options.mail_user+">") % (Header('发布任务','utf-8'),)
    msg['To'] = options.to_user
    msg["Accept-Charset"]="ISO-8859-1,utf-8"
    msg['Date'] = formatdate()
    server = smtplib.SMTP()
    try:
        server.connect(options.mail_server)
        server.login(options.mail_user,options.mail_password)
        server.sendmail(options.mail_user, options.to_user, msg.as_string())
        app_log.error('send mail successfully')
    except Exception, e:
        app_log.info('send mail error: %s', e)
示例#7
0
 def mail(self, conntext):
     if (float(sys.getsizeof(conntext)) / 1024 / 1024) < 2:  #2MB
         msg = MIMEText(conntext, _charset='utf-8')
         msg['Subject'] = self.subject
         msg['From'] = self.user
         msg['To'] = ",".join(self.to_list)
         try:
             server = smtplib.SMTP()
             server.connect(self.smtp, "25")
             # server.starttls()
             server.login(self.user, self.passwd)
             server.sendmail(self.user, self.to_list, msg.as_string())
             server.quit()
             return self.status(True, '')
         except Exception, e:
             return self.status(False, e)
示例#8
0
def create_message(sender, to, subject, message_text):
    """Create a message for an email.

    Args:
    sender: Email address of the sender.
    to: Email address of the receiver.
    subject: The subject of the email message.
    message_text: The text of the email message.

    Returns:
    An object containing a base64url encoded email object.
    """
    message = MIMEText(message_text)
    message['to'] = to
    message['from'] = sender
    message['subject'] = subject
    return {'raw': base64.urlsafe_b64encode(message.as_string())}
示例#9
0
 def send_mailText(self,sender,to_list,content,title):
     print 'nice'
     print title ,content
     mail_host="smtp.163.com"
     mail_user=sender[0]
     mail_pass =sender[2]
     # me="hello"+"<"+mail_user+"@"+mail_postfix+">"
     me = sender[1]
     msg = MIMEText(content,_subtype='plain',_charset='gb2312')
     msg['Subject'] = title
     msg['From'] = me
     msg['To'] = ";".join(to_list)
     try:
         server = smtplib.SMTP()
         server.connect(mail_host)
         server.login(mail_user,mail_pass)
         server.sendmail(me, to_list, msg.as_string())
         server.close()
         return True
     except Exception, e:
         print str(e)
         return False