Code snippets: August 2008 Archives
Some of us does not have a approved SMTP server on our development server, or are working outside the office. So how do you then send email when using Django as your python framework?
The answer is simple: Gmail
You will need:
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '<user>@gmail.com'
EMAIL_HOST_PASSWORD = '<password>
EMAIL_PORT = 587
EMAIL_USE_TLS = True
That's it. Given, you can't use it in your production environment. But it works like a charm during development. And if you need help sending html mail with alternative content (html+txt), check out Ross Poultons article Easy Multi-Part E-Mails with Django
The answer is simple: Gmail
You will need:
- A gmail account
- Django (of course...)
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '<user>@gmail.com'
EMAIL_HOST_PASSWORD = '<password>
EMAIL_PORT = 587
EMAIL_USE_TLS = True
That's it. Given, you can't use it in your production environment. But it works like a charm during development. And if you need help sending html mail with alternative content (html+txt), check out Ross Poultons article Easy Multi-Part E-Mails with Django
By default, both Firefox and IE limits the number of connections per server too 2. Upping the value to 6-8 is a good way if you want to:
Firefox:
Go to the location bar and type:
about:config
This will give you all configuration alternatives for firefox, find (or search):
network.http.max-persistent-connections-per-server
and make it above 2, below 10.
IE
Following these instructions..
- Browser faster (the connection limit is a usual bottleneck for fast connections)
- Download more then 2 files at the same time
Firefox:
Go to the location bar and type:
about:config
This will give you all configuration alternatives for firefox, find (or search):
network.http.max-persistent-connections-per-server
and make it above 2, below 10.
IE
Following these instructions..
Tradedoubler is one of Swedens largest ad networks. However, all ads are served over a none secure connection (https). This is fine for regular users, but if you are building a member only site with secure login (https) you are out of luck:
Serving both secure (https, all your content) and none secure (the ads) brings up a IE message asking the user if they want to "show unsecure objects" on the site. Every time the users loads a page. (In swedish: "Denna sida innehåller både säkra och osäkra objekt. Vill du visa osäkra objekt?")
So how do we solve this problem?
Usual Tradedoubler Ad code is something like this:
<script type="text/javascript">
var uri = 'http://impse.tradedoubler.com/imp?type(js)g(<id>)a(<id>)' + new String (Math.random()).substring (2, 11);
document.write('<sc'+'ript type="text/javascript" src="'+uri+'" charset="ISO-8859-1"></sc'+'ript>');
</script>
As you can see, the url is http://impse. None secure. But a little known fact is that tradedoubler ads can also be served over https://tracker.tradedoubler.com. As far as I know there is no difference.
So we do what many organisations do (such as google analytics). We let javascript check if the maste page was served over http and https. Such as this:
<script type="text/javascript">
var tdHost = ( ("https:" == document.location.protocol) ? "https://tracker." : "http://imp." );
var uri = tdHost + 'tradedoubler.com/imp?type(js)pool(<id>)a(<id> + new String (Math.random()).substring (2, 11);
document.write('<sc'+'ript type="text/javascript" src="'+uri+'" charset="ISO-8859-1"></sc'+'ript>');
</script>
Simple as that. If it's https it will use https://tracker.tradedoubler.com, if it's http it will use the regular http://imp.tradedoubler.com
The script is hardly perfect, but it works for most purposes. Tradedoubler has been notified of the problem, and hopefully they will implement a solution.
Good luck with your ad serving...
Serving both secure (https, all your content) and none secure (the ads) brings up a IE message asking the user if they want to "show unsecure objects" on the site. Every time the users loads a page. (In swedish: "Denna sida innehåller både säkra och osäkra objekt. Vill du visa osäkra objekt?")
So how do we solve this problem?
Usual Tradedoubler Ad code is something like this:
<script type="text/javascript">
var uri = 'http://impse.tradedoubler.com/imp?type(js)g(<id>)a(<id>)' + new String (Math.random()).substring (2, 11);
document.write('<sc'+'ript type="text/javascript" src="'+uri+'" charset="ISO-8859-1"></sc'+'ript>');
</script>
As you can see, the url is http://impse. None secure. But a little known fact is that tradedoubler ads can also be served over https://tracker.tradedoubler.com. As far as I know there is no difference.
So we do what many organisations do (such as google analytics). We let javascript check if the maste page was served over http and https. Such as this:
<script type="text/javascript">
var tdHost = ( ("https:" == document.location.protocol) ? "https://tracker." : "http://imp." );
var uri = tdHost + 'tradedoubler.com/imp?type(js)pool(<id>)a(<id> + new String (Math.random()).substring (2, 11);
document.write('<sc'+'ript type="text/javascript" src="'+uri+'" charset="ISO-8859-1"></sc'+'ript>');
</script>
Simple as that. If it's https it will use https://tracker.tradedoubler.com, if it's http it will use the regular http://imp.tradedoubler.com
The script is hardly perfect, but it works for most purposes. Tradedoubler has been notified of the problem, and hopefully they will implement a solution.
Good luck with your ad serving...
