mime-message

Encoding of headers in MIMEText

独自空忆成欢 提交于 2019-11-28 04:24:36
问题 I'm using MIMEText to create an email from scratch in Python 3.2, and I have trouble creating messages with non-ascii characters in the subject. For example from email.mime.text import MIMEText body = "Some text" subject = "» My Subject" # first char is non-ascii msg = MIMEText(body,'plain','utf-8') msg['Subject'] = subject # <<< Problem probably here text = msg.as_string() The last line gives me the error UnicodeEncodeError: 'ascii' codec can't encode character '\xbb' in position 0: ordinal

MimeMessage.saveChanges is really slow

﹥>﹥吖頭↗ 提交于 2019-11-27 15:54:34
The following test is taking around 5 seconds to execute due to the inclusion of m.saveChanges() . import org.junit.Before; import org.junit.Test; import javax.mail.MessagingException; import javax.mail.Session; import javax.mail.internet.MimeMessage; import java.io.IOException; import java.util.Properties; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @Test public void test1() throws MessagingException, IOException { Session s = Session.getDefaultInstance(new Properties()); MimeMessage m = new MimeMessage(s); m

Setting the from name in a javax.mail.MimeMessage?

北慕城南 提交于 2019-11-27 01:27:19
问题 Currently, our application uses a javax.mail to send email, using javax.mail.MailMessage. We set the From headers of the email this way: Message msg = new MimeMessage(mailSession); msg.setFrom(new InternetAddress("mail@companyxyz.com")); This works just fine, but we'd like to make the "From" section a little more user-friendly. Currently, someone receiving an email will see "mail@companyxyz.com" in the "From" section of their inbox. Instead, we'd like them to see "Company XYZ" there. I figure