Hi,
I have the following code in my app:
    #import Mail
    from gluon.tools import Mail
    mail=Mail()
    #specify server
    mail.settings.server='mail.mydomain.com:26'
    mail.settings.login=None or 'usern...@mydomain.com:password'
    #specify address to send as
    mail.settings.sender='usern...@mydomain.com'
    #send the message
    mail.send(to='someaddr...@someserver.com', subject='something',
message='blahblahblah')
As taken from
    
http://wiki.web2py.com/Sending_Email_with_Plain_Text_HTML_Versions_plus_Attachments
The script kept failing with smtp error 550 (administrative
prohibition).
After some research with the hosting tech guys, this entry was found
in sendmail log:
    rejected after DATA: there is no valid sender in any header line
This gave me a clue concerning the problem: I figured that the
outbound message is malformed.
I debugged the Mail.send procedure and saw, that the DATA is as
follows:

Content-Type: multipart/related;
boundary="===============1127073748=="
MIME-Version: 1.0
To: someaddr...@someserver.com
Subject: something

--===============1127073748==
Content-Type: multipart/alternative;
boundary="===============1727006280=="
MIME-Version: 1.0

--===============1727006280==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit

blahblahblah
--===============1727006280==--
--===============1127073748==--

Note, that "From" is missing, which corresponds to the entry in the
log file.

I  changed Mail.send() procedure by adding the following line:
     payload['From'] =
self.settings.sender.decode(encoding).encode('utf-8')
at file tools.py, line 259, immediately below the line
     payload = MIMEMultipart.MIMEMultipart('related')

now the new DATA is as follows:

Content-Type: multipart/related;
boundary="===============0875610869=="
MIME-Version: 1.0
From: usern...@mydomain.com
To: someaddr...@someserver.com
Subject: something

--===============0875610869==
Content-Type: multipart/alternative;
boundary="===============0956429397=="
MIME-Version: 1.0

--===============0956429397==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit

blahblahblah
--===============0956429397==--
--===============0875610869==--

At this time the messages pass successfully.
I wonder whether I am missing something (perhaps, somethings in
mail.settings) and there's a way to fix this problem without modifying
the framework code.
Thanks!


-- 
To unsubscribe, reply using "remove me" as the subject.

Reply via email to