类javax.mail.internet.MailDateFormat源码实例Demo

下面列出了怎么用javax.mail.internet.MailDateFormat的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: DKIM-for-JavaMail   文件: MimeMailExample.java
public static void main(String args[]) throws Exception {
	
	// read test configuration from test.properties in your classpath
	Properties testProps = TestUtil.readProperties();
	
	// generate string buffered test mail
	StringBuffer mimeMail = new StringBuffer();
	mimeMail.append("Date: ").append(new MailDateFormat().format(new Date())).append("\r\n");
	mimeMail.append("From: ").append(testProps.getProperty("mail.smtp.from")).append("\r\n");
	if (testProps.getProperty("mail.smtp.to") != null) {
		mimeMail.append("To: ").append(testProps.getProperty("mail.smtp.to")).append("\r\n");
	}
	if (testProps.getProperty("mail.smtp.cc") != null) {
		mimeMail.append("Cc: ").append(testProps.getProperty("mail.smtp.cc")).append("\r\n");
	}
	mimeMail.append("Subject: ").append("DKIM for JavaMail: MimeMailExample Testmessage").append("\r\n");
	mimeMail.append("\r\n");
	mimeMail.append(TestUtil.bodyText);

	// get a JavaMail Session object 
	Session session = Session.getDefaultInstance(testProps, null);

	
	
	///////// beginning of DKIM FOR JAVAMAIL stuff
	
	// get DKIMSigner object
	DKIMSigner dkimSigner = new DKIMSigner(
			testProps.getProperty("mail.smtp.dkim.signingdomain"),
			testProps.getProperty("mail.smtp.dkim.selector"),
			testProps.getProperty("mail.smtp.dkim.privatekey"));

	/* set an address or user-id of the user on behalf this message was signed;
	 * this identity is up to you, except the domain part must be the signing domain
	 * or a subdomain of the signing domain.
	 */ 
	dkimSigner.setIdentity("[email protected]"+testProps.getProperty("mail.smtp.dkim.signingdomain"));

	// construct the JavaMail message using the DKIM message type from DKIM for JavaMail
	Message msg = new SMTPDKIMMessage(session, new ByteArrayInputStream(mimeMail.toString().getBytes()), dkimSigner);

	///////// end of DKIM FOR JAVAMAIL stuff

	// send the message by JavaMail
	Transport transport = session.getTransport("smtp");
	transport.connect(testProps.getProperty("mail.smtp.host"),
			testProps.getProperty("mail.smtp.auth.user"),
			testProps.getProperty("mail.smtp.auth.password"));
	transport.sendMessage(msg, msg.getAllRecipients());
	transport.close();
}
 
源代码2 项目: ImapNote2   文件: UpdateThread.java
public void WriteMailToNew(OneNote note, String usesticky, String noteBody) throws MessagingException, IOException {
  String body = null;

  // Here we add the new note to the "new" folder
  //Log.d(TAG,"Add new note");
  Properties props = new Properties();
  Session session = Session.getDefaultInstance(props, null);
  MimeMessage message = new MimeMessage(session);
  if (usesticky.equals("true")) {
    body = "BEGIN:STICKYNOTE\nCOLOR:" + this.color + "\nTEXT:" + noteBody +
           "\nPOSITION:0 0 0 0\nEND:STICKYNOTE";
    message.setText(body);
    message.setHeader("Content-Transfer-Encoding", "8bit");
    message.setHeader("Content-Type","text/x-stickynote; charset=\"utf-8\"");
  } else {
    message.setHeader("X-Uniform-Type-Identifier","com.apple.mail-note");
    UUID uuid = UUID.randomUUID();
    message.setHeader("X-Universally-Unique-Identifier", uuid.toString());
    body = noteBody;
    body = body.replaceFirst("<p dir=ltr>", "<div>");
    body = body.replaceFirst("<p dir=\"ltr\">", "<div>");
    body = body.replaceAll("<p dir=ltr>", "<div><br></div><div>");
    body = body.replaceAll("<p dir=\"ltr\">", "<div><br></div><div>");
    body = body.replaceAll("</p>", "</div>");
    body = body.replaceAll("<br>\n", "</div><div>");
    message.setText(body, "utf-8", "html");
    message.setFlag(Flags.Flag.SEEN,true);
  }
  message.setSubject(note.GetTitle());
  MailDateFormat mailDateFormat = new MailDateFormat();
  // Remove (CET) or (GMT+1) part as asked in github issue #13
  String headerDate = (mailDateFormat.format(new Date())).replaceAll("\\(.*$", "");
  message.addHeader("Date", headerDate);
  //déterminer l'uid temporaire
  String uid = Integer.toString(Math.abs(Integer.parseInt(note.GetUid())));
  File directory = new File ((ImapNotes2.getAppContext()).getFilesDir() + "/" +
          Listactivity.imapNotes2Account.GetAccountname() + "/new");
  //message.setFrom(new InternetAddress("ImapNotes2", Listactivity.imapNotes2Account.GetAccountname()));
  message.setFrom(Listactivity.imapNotes2Account.GetAccountname());
  File outfile = new File (directory, uid);
  OutputStream str = new FileOutputStream(outfile);
  message.writeTo(str);

}
 
 类所在包
 同包方法