guys, I am new to pylons turbomail can't you write a class?

import datetime, os, socket
import sys, smtplib, MimeWriter, base64, StringIO, getopt
import mimetypes, mimetools


class SendMailer:
    def __init__(self, sender, to, subject, text, attachments):
        self.sender = sender
        self.to = to
        self.subject = subject
        self.text = text
        self.attachments = attachments
        """
        Usage:
        SendMailer()
        Params:
        sender: sender's email address
        to: receipient email address
        text: Email message body main part.
        attachments: list of files to attach
        """
        message = StringIO.StringIO()
        writer = MimeWriter.MimeWriter(message)
        writer.addheader('To', self.to)
        writer.addheader('From', self.sender)
        writer.addheader('Subject', self.subject)
        writer.addheader('MIME-Version', '1.0')
        writer.startmultipartbody('mixed')

        # start with a text/plain part
        part = writer.nextpart()
        body = part.startbody('text/plain')
        part.flushheaders()
        body.write(self.text)

        # now add the attachments
        if self.attachments is not None:
            for a in self.attachments:
                filename = os.path.basename(a)
                ctype, encoding = mimetypes.guess_type(a)
                if ctype is None:
                    ctype = 'application/octet-stream'
                    encoding = 'base64'
                elif ctype == 'text/plain':
                    encoding = 'quoted-printable'
                else:
                    encoding = 'base64'

                part = writer.nextpart()
                part.addheader('Content-Transfer-Encoding', encoding)
                body = part.startbody("%s; name=%s" % (ctype, filename))
                mimetools.encode(open(a, 'rb'), body, encoding)

        # that's all falks
        writer.lastpart()

        # send the mail
        smtp = smtplib.SMTP(SERVER, 25)
        smtp.set_debuglevel(1)
        smtp.sendmail(sender, to, message.getvalue())
        smtp.quit()




PORT = 25
SERVER = 'mailserverofisp'

email = SendMailer(sender='[email protected]', to='
[email protected]', subject='Reports for recipient', text='Monthly
reports for recipient.\n\n', attachments=attach)


On Mon, Aug 1, 2011 at 6:38 AM, gary clark <[email protected]> wrote:

> Ok I will have a wee' look at that today.
>
>
> On Mon, Aug 1, 2011 at 8:36 AM, Mariano Mara <[email protected]>wrote:
>
>> On 01.08.11 06:26, gazza wrote:
>> > Hello,
>> >
>> > I want to use a tool to send email notifications when events happen?
>> > Any ideas on what the best tool to use i.e sendmail. I need to send it
>> > to gmail and yahoo etc.
>> >
>>
>> I'm using TurboMail[1] with my pylons applications and pyramid_mailer[2]
>> with
>> my pyramid applications. Both are really simple to setup and run and work
>> ok.
>>
>> [1] http://packages.python.org/TurboMail/
>>
>> [2] http://packages.python.org/pyramid_mailer/
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "pylons-discuss" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/pylons-discuss?hl=en.
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/pylons-discuss?hl=en.
>



-- 
David Garvey

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to