i have a simple email sender using coldfusion 10 that first allows users to upload and then attach those files to the email.
those files are attached like;
<CFMAILPARAM FILE="#file#" DISPOSITION="attachment" TYPE="#type#/#subtype#">
today we uploaded and sent out two attachments with filenames like;
Blah_Blah_something_off_Brazil_Site-Table_4.docx
Blah_something_off_Brazil_Sites-map.pdf
but in outlook/live mail the attachments were being shown as;
ATT00247.docx
ATT00249.pdf
i've had trouble before with outlook/live mail and attachments being given different filenames, but that was down to spaces in the filename. these files have no spaces. so i had a look at the email source, which was showing the attachments as;
Blah_Blah_something_off_Bra%7ail_Site-Table_4.docx
Blah_something_off_Bra%7ail_Sites-map.pdf
its replaced the z's with the %7a
i had a look at the email source in thunderbird, which was displaying the names correctly, but even there, in the source, the filenames had the z's replaced with %7a
so i created a text file, saved it as brazil.txt, uploaded and sent it out
in the email source in outlook and thunderbird, it came through as;
bra%7ail.txt
i know that a %7a is a url encoded z. the uploaded/saved on server file doesn't have that - it has the z. its only when emailed as an attachment that the z's get changed to %7a
anyone have any idea whats going on?! why doesn't coldfusion cfmail like the letter z?!
edit - so i just created a text file called
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.txt
and it came through as;
abcdefghijklmnopqrstuvwxy%7aABCDEFGHIJKLMNOPQRSTUVWXYZ.txt
so its only lowercase z's that get changed ...
addition
well, i fixed it - removing the TYPE="#type#/#subtype#" did the job, but i don't why that was causing trouble. below is what is was filling in for the type/subtype ( which came from the upload/cffile ) for each of the files;
zanzibar1.txt - text/plain
Blah_Something_off_Brazil_Sites-map-test1.pdf - application/pdf
Blah_Blah_Something_off_Brazil_Site-Table_4-test1.docx - application/vnd.openxmlformats-officedocument.wordprocessingml.document
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1.txt - text/plain
all the email clients i've tested don't seem to care about the type/subtype missing and they all display the correct filename. but i don't see whats wrong with type/subtype ...
Related
I have some filenames stored with the # symbol. If I send a GET request to retrieve them I am running into problems as I believe GET requests are cut off at anchors within the path?
ex:
s3.amazonaws.com/path/to/my_file.jpg
vs: my browser stops looking at the #
s3.amazonaws.com/path/to/my_other_#file.jpg
is there a way to retrieve the file or will I have to change filenames so they do not contain #'s?
You need to encode your path as URL which would replace # with %23.
Check out this for URL encoding. https://www.w3schools.com/tags/ref_urlencode.asp
In JavaScript you can use encodeURI() to get it encoded.
https://www.w3schools.com/jsref/jsref_encodeURI.asp
Working on a Django/React app. I have some verification emails links that look like the following:
https://test.example.com/auth/security_questions/f=ru&i=101083&k=7014c315f3056243534741610545c8067d64d747a981de22fe75b78a03d16c92
In dev env this works fine, but now that I am getting it ready for production, it isn't working. When I click on it, it converts it to:
https://test.example.com/auth/security_questions/f%3Dru&i%3D101083&k%3D7014c315f3056243534741610545c8067d64d747a981de22fe75b78a03d16c92/
This prevents react-router-dom from matching the correct URL, so a portion of the web application does not load properly.
The link is constructed using the following.
link = '%s/auth/security_questions/f=%s&i=%s&k=%s' % \
('https://test.example.com', 'ru', user.id, user.key)
Also, here is the url() that is catching the route:
url(r'^(?:.*)/$', TemplateView.as_view(template_name='index.html')),
These variables are supposed to be query parameters in a GET request. When you construct the link, you'll need to have a question mark in there somewhere separating the URL from the query string:
https://test.example.com/auth/security_questions/?f=ru&i=101083&k=7014c315...
^
|___ here
The conversion of = to url-encoded %3D etc is correct, and equivalent. Sometimes variables are part of the URL directly, but webapps don't use &-separated key/value pairs in that case.
My Python script takes a list of lists and creates the text of an email body by joining the inner lists' elements with a "," and appends each of these with a newline like so:
for row in rows:
emailBody += ",".join(row) + "\n"
(I know that I can do something similar using the CSV module, but I'm aiming to do without it - at least for now.)
Then later it sends the email by using:
import smtplib
from email.mime.text import MIMEText
smtpServer = serverDNS
msg = MIMEText(emailBody, "plain")
msg['from'] = fromAddress
msg['to'] = ", ".join(recipients)
msg['subject'] = subject
smtp = smtplib.SMTP(smtpServer)
smtp.sendmail(msg['from'], recipients, msg.as_string())
smtp.quit()
This works fine, except that the newline on the first line gets ignored and the first two lines end up on one line. The newline on every other line is just fine.
If I manually add an extra newline to the last item of the first line, then the email has TWO newlines after the first line, so that there is a blank line between the first two lines.
What is going on here? How can I get this to behave as expected?
Note that the first line (the first list) consists of a bunch of hard-coded strings. So it's a very simple list. All the other lines are dynamically generated, but are all simple string values in the end (otherwise the 'join' would complain, right?).
If I simply print emailBody, it prints fine. It is only when converting it to an email that the first line's newline gets lost.
I've also tried using "\r\n" instead of just "\n". Same result.
This appears to be an OUTLOOK "Feature" (I'd call it a bug!), not a problem with my Python code. Unfortunately, I'm stuck with Outlook at work. But I found that if I send the email to both the work address and my private address, it shows up perfectly fine on my private email, but wrong in my work email!
Then I noticed that in Outlook, there is a line of small grey text near the top of the email that says "Extra line breaks in this message were removed." Clicking on this line restores the line breaks and the email is then displayed correctly!
Any idea why Outlook does this? Any idea why it does this on some lines and not others, and how I can code my Python to send emails that wont make Outlook "fix" them?
Outlook Fix:
Unfortunately, I can't do this for all the people that may receive these emails. However, I did find a preference in Outlook for "Remove extra line breaks in plain text messages" which was on, so I've turned it off, and this has resolved the problem in my Outlook client, at least.
I will have to communicate this to all other recipients of these emails if I cannot figure out how to format them so that Outlook doesn't try to "Fix" them.
I'm using MimeKit for creating s/mime encrypted mails with attachments.
As soon as an attachment name has special chars, e.g. äüö, the attachemnt name gets lost and is displayed like "unnamend attachment 123.dat" in Outlook.
Unencrypted mails do fine, so the only difference is just msg.Encrypt(context).
Are there some constraints in MimeKit regarding this use case or do I have to do more to get this working?
Iterate over the ContentType and ContentDisposition parameters of the attachment (before encrypting) and set the EncodingMethod of each parameter to ParameterEncodingMethod.Rfc2047.
The problem is probably that Outlook can't handle rfc2231-style encoding of parameter values.
example:
foreach (var param in attachment.ContentType.Parameters)
param.EncodingMethod = ParameterEncodingMethod.Rfc2047;
foreach (var param in attachment.ContentDisposition.Parameters)
param.EncodingMethod = ParameterEncodingMethod.Rfc2047;
When im trying to send a mail with django send mail only the html message is coming and not the normal message i want to know the difference between both.
Is there any best way to send mails through template or html files because i want a comming mailing system in my app.
Note:- the difference is of more important.
THIS IS WHAT I DID
msg_html = (' HELLLOOOOO')
msg_plain = 'Normalallalaa
send_mail("titleeeee", msg_plain,"sender#test",["reciever#tese",],html_message=msg_html)
My mail contained only Hello in bold
Where did my message go.
The problem is that some (old or specifically configured) email clients won't display HTML messages, therefore you need to make sure all your users can read your emails properly. If you decide to send just text, then users capable of getting HTML messages won't benefit from it.
This is the strategy I follow:
I use django.template.loader.render_to_string to render a template with a given context. The value this function returns is a string with a message in HTML.
html_text = render_to_string(template, context)
Then I create a plain text message based on the HTML message (for instance, by using a package named html2text):
plain_text = html2text(html_text)
And finally I send the email with django.core.mail.send_mail, passing html_text and plain_text as parameters.
Message is plain text, while html_message is a message formatted using HTML. If you set both, probably your email client is displaying the HTML version.