jfmcreatenewemail.java

来自「java邮件源程序」· Java 代码 · 共 76 行

JAVA
76
字号
/* * Created on 2004.08.25 * JFreeMail - Java mail component * Copyright (C) 2004 Dalibor Krleza *  * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. *  * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Lesser General Public License for more details. *  * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */ package org.jfreemail.demo;import java.io.FileInputStream;import org.jfreemail.core.*;import org.jfreemail.smtp.*;/** * This demo shows how to create and send new E-mail. */public class JfmCreateNewEmail {	public static void main(String[] args) {		try {			/*			 * Creating email object with default text message to send.			 */			JfmEmail email=JfmEmail.CreateTextEmail(				"dalibor@server.domain",				new String[]{"marty@server.domain"},				new String[]{"john@server.domain"},				"Contact info",				new String[]{"Hi Marty and John!\r\n",									 "\r\n",									 "I appreciate you are informing yourself about my\r\n",									 "look. I'm sending you my picture in attachment\r\n",									 "\r\n",									 "Dalibor\r\n"},				"utf-8");			/*			 * Loading picture from hard disk.			 */			FileInputStream fis=new FileInputStream("/home/dalibor/pic.jpg");			byte[] attachment=new byte[fis.available()];			fis.read(attachment);			fis.close();						/*			 * Adding attachment.			 */			email.addEmailAttachment("pic.jpg","image/jpeg",attachment);			/*			 * Creating SMTP object. Immediate authetication.			 */			JfmSMTP smtp=new JfmSMTP("mail.server.domain",0,				JfmConsts.SMTP_LOGIN,"dalibor","secret111");			/*			 * Send out modified E-mail.			 */			smtp.sendMail(email);			smtp.close();		} catch(Exception exc) {			System.out.println(exc.getMessage());		}	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?