Re: HttpResponse HTML links missing URL prefix when emailing

2009-01-08 Thread Eric Abrahamsen


On Jan 8, 2009, at 8:37 PM, Eki wrote:

>
> Hi guys,
>
> I'm implementing a view which sends a (nightly) status report email.
> The code works mostly fine. I can both receive the email and see the
> result rendered as I query the view. The HTML shown and emailed is
> gotten from the same response object. However, the links included in
> the report only work in the browser view, but not in the email. For
> the email, the links are rendered with a default prefix of "http://;,
> and they are missing the domain name and https protocol specifier.
> I've been digging, but so far unable to find any reason why the prefix
> should be lost between two lines of code.

My guess is that in the HTML all the links come out as absolute links,  
minus the hostname. Ie href="/home/leaf/page/", rather than 
href="http://www.domain.com/home/leaf/page 
". That's usually how it is on a webpage, because the server assumes  
that all links are relative to the same domain. It's not that your  
code is changing between html and email, but that the domain is left  
out altogether in both cases – which works fine on a webserver, not so  
well when clicking a link in an email message.

You might want to use a separate template for the emails, or else put  
the current HTTP_HOST in a variable and resolve that for the links in  
both html and email.

Hope that helps,
Eric


>
>
> Here are the relevant parts of my functions:
>
> def send_daily(request):
>...
>
>response = render_to_response('email/status.html',
>{ ... a bunch of context stuff ... })
>send_email('Daily project status', 'sen...@nowhere.not',
> 'recei...@nowhere.not',
>'This report can only be viewed in HTML, which appears not to
> be supported by your email client.',
>response._get_content())
>return response
>
> def send_email(subject, from_email, to, text, html):
>msg = EmailMultiAlternatives(subject, text, from_email, [to])
>msg.attach_alternative(html, "text/html")
>msg.send()
>
> Thanks for any hints.
>
> -- Eki
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



HttpResponse HTML links missing URL prefix when emailing

2009-01-08 Thread Eki

Hi guys,

I'm implementing a view which sends a (nightly) status report email.
The code works mostly fine. I can both receive the email and see the
result rendered as I query the view. The HTML shown and emailed is
gotten from the same response object. However, the links included in
the report only work in the browser view, but not in the email. For
the email, the links are rendered with a default prefix of "http://;,
and they are missing the domain name and https protocol specifier.
I've been digging, but so far unable to find any reason why the prefix
should be lost between two lines of code.

Here are the relevant parts of my functions:

def send_daily(request):
...

response = render_to_response('email/status.html',
{ ... a bunch of context stuff ... })
send_email('Daily project status', 'sen...@nowhere.not',
'recei...@nowhere.not',
'This report can only be viewed in HTML, which appears not to
be supported by your email client.',
response._get_content())
return response

def send_email(subject, from_email, to, text, html):
msg = EmailMultiAlternatives(subject, text, from_email, [to])
msg.attach_alternative(html, "text/html")
msg.send()

Thanks for any hints.

-- Eki

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---