Exemplo n.º 1
0
    def test_set_group_variables_fail(self):
        """this test ensure if there's at least one data problem in the dictionary
		passed to the setVariables function at least one error is raised."""
        data = {
            'order': 'pizza',
            '*to': '*****@*****.**',
        }
        rcpt = Recipient('*****@*****.**')
        self.assertRaises(PmtaRecipientError, rcpt.defineVariables, data)
Exemplo n.º 2
0
    def test_set_default_variables_fail(self):
        """this tests the defineVariable function of the Recipient object to ensure
		it fails if you set default variables."""
        rcpt = Recipient('*****@*****.**')
        self.assertRaises(PmtaRecipientError, rcpt.defineVariable, '*to',
                          '*****@*****.**')
    def Inject(self, address):
        try:
            print 'Connecting to %s on port %s' % (self.__smtp_server_hostname, self.__smtp_server_port)
            from_address = self.__campaign_handler.GetFrom()

            if self.__use_from == True:
                from_parts = from_address.split('@') 
                redirect_domain = from_parts[1]
            else:
                redirect_domain = self.__campaign_handler.GetDomain()

                if redirect_domain == None:
                    raise ValueError('The domains file can not be empty')

            rcpt = Recipient(address)
            rcpt.defineVariable('to', address)
            rcpt.defineVariable('friendlyfrom', self.__campaign_handler.GetFriendlyFrom())
            rcpt.defineVariable('from', from_address)
            rcpt.defineVariable('subject', self.__campaign_handler.GetSubject())
            rcpt.defineVariable('date', time.strftime("%a, %d %b %Y %H:%M:%S %z", time.gmtime()))
            rcpt.defineVariable('*parts', '1')
            rcpt.defineVariable('rdomain', redirect_domain)

            email = Message(from_address)

            email.addRecipient(rcpt)
            email.addMergeData(self.__campaign_handler.GetBody())

            conn = Connection(str(self.__smtp_server_hostname), int(self.__smtp_server_port))
            conn.submit(email)

        except PmtaError as e:
            print 'Connecting to %s on port %s' % (self.__smtp_server_hostname, self.__smtp_server_port)
            print e
Exemplo n.º 4
0
    def test_empty_variables_fail(self):
        """this tests the defineVariable function of the Recipient object to ensure
		it fails if no variables are passed."""
        rcpt = Recipient('*****@*****.**')
        self.assertRaises(PmtaRecipientError, rcpt.defineVariable)
Exemplo n.º 5
0
from port25.submitter.message import Message, PmtaMessageError
from port25.submitter.recipient import Recipient, PmtaRecipientError
from port25.submitter.connection import Connection, PmtaConnectionError
from port25 import PmtaError

try:

	list = ('*****@*****.**', '*****@*****.**',)
	list_data = {'*****@*****.**': {'name': 'Peter'}, '*****@*****.**': {'name': 'Rich'},}
	data = "From: [email protected]\12To:[*to]\12Subject: Your Order has been processed\12Mime-Version: 1.0\12Content-type: multipart/alternative;boundary=\"PMTAMimeBoundry\"\12[name]<br><br>Hey your order of a [order] has come in.  Please stop by and give us your money.<br><br>Tech Team <br>"

	msg = Message('*****@*****.**')

        rcpt = None
	for item in list:
		rcpt = Recipient(item)
		rcpt.defineVariable('name', list_data[item]['name'])
		rcpt.defineVariable('order', 'pizzas')
		rcpt.defineVariable('*parts', '1')
		msg.addRecipient(rcpt)

	msg.addMergeData(data) 
	conn = Connection()
	conn.submit(msg)
	
except PmtaError, e:
        print e 
except Exception, e:
        print "Some other error"
        print e.args