コード例 #1
0
ファイル: comsmtp.py プロジェクト: neraware/X4GA
 def send(self, 
          SendFrom=None, 
          Subject="", 
          Message="", 
          SendTo=None, 
          SendCC=None, 
          SendBCC=None, 
          Attachments=None):
     
     self.error = None
     
     SendFrom = SendFrom or SENDER
     if isinstance(SendTo, basestring):
         SendTo = [SendTo]
     
     self.SendFrom =    SendFrom
     self.SendTo =      SendTo
     self.Subject =     Subject
     self.Message =     Message
     self.SendCC =      SendCC
     self.SendCCN =     SendBCC
     self.Attachments = []+(Attachments or [])
     
     self.msg = MIMEMultipart()
     self.msg['From'] = self.SendFrom or ''
     self.msg['To'] = COMMASPACE.join(SendTo)
     self.msg['Date'] = formatdate(localtime=True)
     self.msg['Subject'] = Subject
     
     self.msg.attach(MIMEText(Message, _charset='utf-8'))
     
     for attach in self.Attachments:
         f = open(attach, 'rb')
         part = MIMEBase('application', "octet-stream")
         part.set_payload(f.read())
         Encoders.encode_base64(part)
         part.add_header('Content-Disposition', 'attachment; filename="%s"'
                         % os.path.basename(attach))
         f.close()
         self.msg.attach(part)
     
     try:
         smtp = smtplib.SMTP(self.smtpServer, int(self.SmtpPort or 0))
         if self.AuthUser:
             if self.AuthTLS:
                 smtp.ehlo()
                 smtp.starttls()
                 smtp.ehlo()
             if not smtp.login(self.AuthUser, self.AuthPswd):
                 self.error = 'Autenticazione fallita'
                 raise AuthFailedException, self.error
         smtp.sendmail(self.SendFrom, self.SendTo, self.msg.as_string() )
         smtp.close()
     except Exception, e:
         self.error = repr(e.args)
         return False
コード例 #2
0
    def send(self,
             SendFrom=None,
             Subject="",
             Message="",
             SendTo=None,
             SendCC=None,
             SendBCC=None,
             Attachments=None):

        SendFrom = SendFrom or SENDER
        if isinstance(SendTo, basestring):
            SendTo = [SendTo]

        self.SendFrom = SendFrom
        self.SendTo = SendTo
        self.Subject = Subject
        self.Message = Message
        self.SendCC = SendCC
        self.SendCCN = SendBCC
        self.Attachments = [] + (Attachments or [])

        self.msg = MIMEMultipart()
        self.msg['From'] = self.SendFrom or ''
        self.msg['To'] = COMMASPACE.join(SendTo)
        self.msg['Date'] = formatdate(localtime=True)
        self.msg['Subject'] = Subject

        self.msg.attach(MIMEText(Message, _charset='utf-8'))

        for attach in self.Attachments:
            f = open(attach, 'rb')
            part = MIMEBase('application', "octet-stream")
            part.set_payload(f.read())
            Encoders.encode_base64(part)
            part.add_header(
                'Content-Disposition',
                'attachment; filename="%s"' % os.path.basename(attach))
            f.close()
            self.msg.attach(part)

        try:
            smtp = smtplib.SMTP(self.smtpServer, int(self.SmtpPort or 0))
            if self.AuthUser:
                if self.AuthTLS:
                    smtp.ehlo()
                    smtp.starttls()
                    smtp.ehlo()
                if not smtp.login(self.AuthUser, self.AuthPswd):
                    raise AuthFailedException, 'Autenticazione fallita'
            smtp.sendmail(self.SendFrom, self.SendTo, self.msg.as_string())
            smtp.close()
        except Exception, e:
            self.error = repr(e.args)
            return False
コード例 #3
0
class SendMail(object):
    """Sends an email to the recipient using the extended MAPI interface
    Subject and Message are strings
    Send{To,CC,BCC} are comma-separated address lists
    MAPIProfile is the name of the MAPI profile"""

    SmtpAddress = None  #Nome server SMTP
    SmtpPort = None  #Numero porta SMTP

    SendTo = None  #Indirizzo destinatario
    Subject = None  #Oggetto del messaggio
    Message = None  #Corpo del messaggio
    SendCC = None  #Indirizzo destinatario in copia
    SendBCC = None  #Indirizzo destinatario in copia nascosta
    Attachments = None  #Lista nomi file da allegare

    AuthUser = None  #Nome utente per autenticazione server
    AuthPswd = None  #Password per autenticazione server
    AuthTLS = None  #Flag autenticazione con TLS
    msg = None  #Oggetto smtp
    error = None  #Specifiche errore invio

    def __init__(self,
                 smtpServer=None,
                 smtpPort=None,
                 authUser=None,
                 authPswd=None,
                 authTLS=None,
                 sendFrom=None):
        object.__init__(self)
        self.smtpServer = smtpServer or SMTP_ADDR
        self.SmtpPort = smtpPort or SMTP_PORT
        if authUser:
            self.AuthUser = authUser
            self.AuthPswd = authPswd
        else:
            self.AuthUser = AUTH_USER
            self.AuthPswd = AUTH_PSWD
        if self.AuthUser:
            self.AuthTLS = authTLS or AUTH_TLS
        else:
            self.AuthTLS = False
        self.SendFrom = sendFrom

    def set_auth(self, user=None, pswd=None, tls=False):
        self.AuthUser = user
        self.AuthPswd = pswd
        self.AuthTLS = tls

    def send(self,
             SendFrom=None,
             Subject="",
             Message="",
             SendTo=None,
             SendCC=None,
             SendBCC=None,
             Attachments=None):

        SendFrom = SendFrom or SENDER
        if isinstance(SendTo, basestring):
            SendTo = [SendTo]

        self.SendFrom = SendFrom
        self.SendTo = SendTo
        self.Subject = Subject
        self.Message = Message
        self.SendCC = SendCC
        self.SendCCN = SendBCC
        self.Attachments = [] + (Attachments or [])

        self.msg = MIMEMultipart()
        self.msg['From'] = self.SendFrom or ''
        self.msg['To'] = COMMASPACE.join(SendTo)
        self.msg['Date'] = formatdate(localtime=True)
        self.msg['Subject'] = Subject

        self.msg.attach(MIMEText(Message, _charset='utf-8'))

        for attach in self.Attachments:
            f = open(attach, 'rb')
            part = MIMEBase('application', "octet-stream")
            part.set_payload(f.read())
            Encoders.encode_base64(part)
            part.add_header(
                'Content-Disposition',
                'attachment; filename="%s"' % os.path.basename(attach))
            f.close()
            self.msg.attach(part)

        try:
            smtp = smtplib.SMTP(self.smtpServer, int(self.SmtpPort or 0))
            if self.AuthUser:
                if self.AuthTLS:
                    smtp.ehlo()
                    smtp.starttls()
                    smtp.ehlo()
                if not smtp.login(self.AuthUser, self.AuthPswd):
                    raise AuthFailedException, 'Autenticazione fallita'
            smtp.sendmail(self.SendFrom, self.SendTo, self.msg.as_string())
            smtp.close()
        except Exception, e:
            self.error = repr(e.args)
            return False

        return True
コード例 #4
0
ファイル: comsmtp.py プロジェクト: ziomar/X4GA
class SendMail(object):
    
    """Sends an email to the recipient using the extended MAPI interface
    Subject and Message are strings
    Send{To,CC,BCC} are comma-separated address lists
    MAPIProfile is the name of the MAPI profile"""
    
    SmtpAddress = None  #Nome server SMTP
    SmtpPort =    None  #Numero porta SMTP
    
    SendTo =      None  #Indirizzo destinatario
    Subject =     None  #Oggetto del messaggio
    Message =     None  #Corpo del messaggio
    SendCC =      None  #Indirizzo destinatario in copia
    SendBCC =     None  #Indirizzo destinatario in copia nascosta
    Attachments = None  #Lista nomi file da allegare
    
    AuthUser =    None  #Nome utente per autenticazione server
    AuthPswd =    None  #Password per autenticazione server
    
    msg =         None  #Oggetto smtp
    error =       None  #Specifiche errore invio
    
    def __init__(self, smtpServer=None, smtpPort=None, authUser=None, authPswd=None, sendFrom=None):
        object.__init__(self)
        self.smtpServer = smtpServer or SMTP_ADDR
        self.SmtpPort = smtpPort or SMTP_PORT
        if authUser:
            self.AuthUser = authUser
            self.AuthPswd = authPswd
        else:
            self.AuthUser = AUTH_USER
            self.AuthPswd = AUTH_PSWD
        self.SendFrom = sendFrom
    
    def set_auth(self, user=None, pswd=None):
        self.AuthUser = user
        self.AuthPswd = pswd
    
    def send(self, 
             SendFrom=None, 
             Subject="", 
             Message="", 
             SendTo=None, 
             SendCC=None, 
             SendBCC=None, 
             Attachments=None):
        
        SendFrom = SendFrom or SENDER
        if isinstance(SendTo, basestring):
            SendTo = [SendTo]
        
        self.SendFrom =    SendFrom
        self.SendTo =      SendTo
        self.Subject =     Subject
        self.Message =     Message
        self.SendCC =      SendCC
        self.SendCCN =     SendBCC
        self.Attachments = []+(Attachments or [])
        
        self.msg = MIMEMultipart()
        self.msg['From'] = self.SendFrom or ''
        self.msg['To'] = COMMASPACE.join(SendTo)
        self.msg['Date'] = formatdate(localtime=True)
        self.msg['Subject'] = Subject
        
        self.msg.attach(MIMEText(Message))
        
        for file in self.Attachments:
            f = open(file, 'rb')
            part = MIMEBase('application', "octet-stream")
            part.set_payload(f.read())
            Encoders.encode_base64(part)
            part.add_header('Content-Disposition', 'attachment; filename="%s"'
                            % os.path.basename(file))
            f.close()
            self.msg.attach(part)
        
        try:
            smtp = smtplib.SMTP(self.smtpServer)
            if self.AuthUser:
                if not smtp.login(self.AuthUser, self.AuthPswd):
                    raise AuthFailedException, 'Autenticazione fallita'
            x = smtp.sendmail(self.SendFrom, self.SendTo, self.msg.as_string() )
            smtp.close()
        except Exception, e:
            self.error = repr(e.args)
            return False
        
        return True