#
# BusyB, an automated build utility.
#
# Copyright (C) 1997-2003
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#
import Base
import busybee.BusyBException
from busybee.Util import sendMail
from busybee import SymbolManager
from Host import Host
from Port import Port
from To import To
from From import From
from Subject import Subject
from Body import Body
class SendMail(Base.Base):
def __init__(self):
Base.Base.__init__(self)
sm=SymbolManager.getInstance()
self.mailHost=Host(sm.getSymbol('MailHost', 'localhost'))
self.mailPort = Port(sm.getSymbol('MailPort', '25'))
self.fromAddr = From(sm.getSymbol('MailFrom', 'buildadmin@no.where'))
self.toAddr = To("$(USER)")
self.subject = Subject(sm.getSymbol('MailSubject', "News from build: "))
self.body = Body("A build was started.")
def setParent(self, parent):
parent.addAction(self)
def setPort(self, p):
self.mailPort = p
def setHost(self, h):
self.mailHost = h
def setFrom(self, f):
self.fromAddr = f
def setTo(self, t):
self.toAddr = t
def setSubject(self, s):
self.subject = s
def setBody(self, b):
self.body = b
def process(self):
self.getLogger().writeln( "Sending mail to " + self.toAddr.getText() )
message=self.buildMessage()
recips = self.toAddr.getText().split(',')
for adressee in recips:
self.getLogger().writeln( "Sending mail to " + adressee )
sendMail(
self.mailHost.getText(), self.mailPort.getText(),
self.fromAddr.getText(), adressee, message )
self.getLogger().writeln( "Sent mail. " )
return 0
def buildMessage(self):
ret = "Subject: " + self.subject.getText() + "\n\n"
ret = ret + self.body.getText() + "\n"
return ret
def __str__(self):
return "send mail"
|