Python preppy producing offensive leading blank line

173 views Asked by At

I'm trying to use preppy to template some email messages, but it inserts a leading blank line which causes SMTP to treat everything as message body in stead of headers. In a standalone test I'm using the following python code:

import preppy

premsg = preppy.getModule('email.prep')
print "========================================="
print premsg.get("[email protected]", "recipient@example,com", "Message Subject", "https://followthislink.com/qwertyuiopp")
print "========================================="

And this template stored in email.prep

{{def(prepToAddr, prepFromAddr, prepSubject, prepLink)}}
To: {{prepToAddr}}
From: "{{prepFromAddr}}
Subject: {{prepSubject}}

Click this link to confirm your email address: {{prepLink}}

Which when run looks like this:

(email)tahaan@Komputer:~/Projects/email$ python prep1.py 
=========================================

To: [email protected]
From: "recipient@example,com
Subject: Message Subject

Click this link to confirm your email address: https://followthislink.com/qwertyuiopp
=========================================
(email)tahaan@Komputer:~/Projects/email$ 

Should I just remove the leading blank line and live with it, or is there something I should be doing different to get the output right?

1

There are 1 answers

0
Robin Becker On

To get this right you need to change the template to eliminate the eol at the end of the {{def()}} ie

{{def(prepToAddr, prepFromAddr, prepSubject, prepLink)}}To: {{prepToAddr}}
From: "{{prepFromAddr}}
Subject: {{prepSubject}}

Click this link to confirm your email address: {{prepLink}}

to eliminate the eol at the end you need an editor that doesn't put an eol in see eg Vim no end of line on last line or eof