I'm using EmailMessage to send emails via Amazon SES in Django. I am currently having trouble inserting new lines in the message. "\n" does not seem to work
How do I go about doing this?
As an example, this is what I've tried:
private void loadingPopup() {
LayoutInflater inflater = this.getLayoutInflater();
final View layout = inflater.inflate(R.layout.popup_welcome, null);
final Button DismissButton = (Button) findViewById(R.id.button_welcomepopup_dismiss);
final PopupWindow Welcome_popupWindow = new PopupWindow(layout, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);
Welcome_popupWindow.setFocusable(false);
Welcome_popupWindow.setTouchable(true);
Welcome_popupWindow.setOutsideTouchable(true);
layout.post(new Runnable() {
public void run() {
Welcome_popupWindow.showAtLocation(layout, Gravity.CENTER, 0, 0);
DismissButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Welcome_popupWindow.dismiss();
}
});
}
});
When I send this email I get:
subject= "Test email with newline"
message = "%s %s is testing an email with a newline. \nCheck out this link too: http://www.example.com" % (user.first_name, user.last_name)
from_string = "<support@example.com>"
email_message = EmailMessage(subject, message, from_string, [user.email])
email_message.send()
However, I expected the email to be formatted like this:
Michael Smith is testing an email with a newline. Check out this link too:
http://www.example.com
答案 0 :(得分:1)
You can use attach_alternative() and provide html - in your case $json = array('tag' => 'Odómetro'); // Original array
$json = json_encode($json); // {"Tag":"Od\u00f3metro"}
$json = json_decode($json); // Od\u00f3metro becomes Odómetro
echo $json->{'tag'}; // Odómetro
echo utf8_decode($json->{'tag'}); // Odómetro
or <p>
will do the trick.
or
<br>
答案 1 :(得分:0)
更好的用法是尝试发送html消息,你可以发送电子邮件为html。在那里你可以像你想要的那样格式化你的消息