麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

JavaMail介紹及發(fā)送一封簡(jiǎn)單郵件

2019-11-14 10:54:24
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

 本文來(lái)自:高爽|Coder,原文地址:http://blog.csdn.net/ghsau/article/details/17839983,#javamail-1.4.5-oth-JPR

       JavaMail spec:http://www.Oracle.com/technetwork/java/javamail-1-149769.pdf

       JAF:http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-java-plat-419418.html#jaf-1.1.1-fcs-oth-JPR

       JavaMail下載好后,我們來(lái)看一下其主要內(nèi)容:

[plain] view plain copy print?在CODE上查看代碼片README.txt:整體介紹JavaMail,需要看一下  docs/javadocs:The JavaMail API javadocs,需要看一下  mail.jar:包括JavaMail API和所有service providers,大部分用戶(hù)只需要該jar包  lib/mailapi.jar :只有JavaMail API  lib/imap.jar:The IMAP service provider  lib/smtp.jar:The SMTP service provider  lib/pop3.jar:The POP3 service provider  lib/dsn.jar:multjavax.mail.session:上下文環(huán)境信息,如服務(wù)器的主機(jī)名、端口號(hào)、協(xié)議名稱(chēng)等  javax.mail.Message:郵件模型,發(fā)送郵件和接收郵件的媒介,封裝了郵件的信息,如發(fā)件人、收件人、郵件標(biāo)題、郵件內(nèi)容等  javax.mail.Transport:連接郵件SMTP服務(wù)器,發(fā)送郵件  javax.mail.Store:連接郵件POP3、IMAP服務(wù)器,收取郵件   %20 %20 %20 通過(guò)這些類(lèi),最終就可以實(shí)現(xiàn)收發(fā)郵件,一個(gè)發(fā)送郵件的簡(jiǎn)單示例:[java] view%20plain copy print?派生到我的代碼片public class JavaMailTest1 {      public static void main(String[] args) throws MessagingException {          Properties props = new Properties();          // 開(kāi)啟debug調(diào)試          props.setProperty("mail.debug", "true");          // 發(fā)送服務(wù)器需要身份驗(yàn)證          props.setProperty("mail.smtp.auth", "true");          // 設(shè)置郵件服務(wù)器主機(jī)名          props.setProperty("mail.host", "smtp.163.com");          // 發(fā)送郵件協(xié)議名稱(chēng)          props.setProperty("mail.transport.protocol", "smtp");                    // 設(shè)置環(huán)境信息          Session session = Session.getInstance(props);                    // 創(chuàng)建郵件對(duì)象          Message msg = new MimeMessage(session);          msg.setSubject("JavaMail測(cè)試");          // 設(shè)置郵件內(nèi)容          msg.setText("這是一封由JavaMail發(fā)送的郵件!");          // 設(shè)置發(fā)件人          msg.setFrom(new InternetAddress("[email protected]"));                    Transport transport = session.getTransport();          // 連接郵件服務(wù)器          transport.connect("java_mail_001", "javamail");          // 發(fā)送郵件          transport.sendMessage(msg, new Address[] {new InternetAddress("[email protected]")});          // 關(guān)閉連接          transport.close();      }  }         最終運(yùn)行后,郵件發(fā)送成功。由于我們開(kāi)啟了debug調(diào)試,在控制臺(tái)可以看到JavaMail和服務(wù)器之間的交互信息記錄,可以發(fā)現(xiàn),和Java Mail(一):telnet實(shí)現(xiàn)發(fā)送收取郵件中telnet下的命令及服務(wù)器反饋信息基本一致。       創(chuàng)建Session對(duì)象時(shí)可能需要的屬性詳細(xì)信息如下:
NameTypeDescription
mail.debugbooleanThe initial debug mode. Default is false.
mail.fromStringThe return email address of the current user, used by the InternetAddressmethodgetLocalAddress.
mail.mime.address.strictbooleanThe MimeMessage class uses the InternetAddress method parseHeader to parse headers in messages. This property controls the strict flag passed to theparseHeader method. The default is true.
mail.hostStringThe default host name of the mail server for both Stores and Transports. Used if themail.protocol.host property isn't set.
mail.store.protocolStringSpecifies the default message access protocol. The SessionmethodgetStore() returns a Store object that implements this protocol. By default the first Store provider in the configuration files is returned.
mail.transport.protocolStringSpecifies the default message transport protocol. The SessionmethodgetTransport() returns a Transport object that implements this protocol. By default the first Transport provider in the configuration files is returned.
mail.userStringThe default user name to use when connecting to the mail server. Used if the mail.protocol.user property isn't set.
mail.protocol.classStringSpecifies the fully qualified class name of the provider for the specified protocol. Used in cases where more than one provider for a given protocol exists; this property can be used to specify which provider to use by default. The provider must still be listed in a configuration file.
mail.protocol.hostStringThe host name of the mail server for the specified protocol. Overrides the mail.host property.
mail.protocol.portintThe port number of the mail server for the specified protocol. If not specified the protocol's default port number is used.
mail.protocol.userStringThe user name to use when connecting to mail servers using the specified protocol. Overrides themail.user property. 

       更新于2014.01.06       文中示例以及以后的示例中所用的郵箱賬戶(hù)均為在163申請(qǐng)的測(cè)試賬戶(hù),分別為java_mail_001至java_mail_004,密碼均為javamail。       本文來(lái)自:高爽|Coder,原文地址:http://blog.csdn.net/ghsau/article/details/17839983,轉(zhuǎn)載請(qǐng)注明。


發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 91成人免费版| 亚洲va久久久噜噜噜久牛牛影视 | 精品国产一区二区三区蜜殿 | 吾色视频 | 91精品国产综合久久婷婷香蕉 | 精国产品一区二区三区 | 黄色大片在线观看 | 中文字幕在线观看www | 美女黄视频在线观看 | 久久精品中文字幕一区二区 | 色污视频在线观看 | 黄色片一区二区 | va视频| 99精彩视频在线观看 | 亚洲最大的成人网 | 国产精品视频在线观看免费 | 成人一级视频 | 中文字幕视频在线播放 | av在线更新 | 国产韩国精品一区二区三区久久 | 亚洲成人精品国产 | 久久精品国产一区二区 | 国产精品久久久久无码av | 国产成人精品网站 | 国产69精品久久久久9999不卡免费 | 国产88久久久国产精品免费二区 | 日本中文字幕高清 | 少妇一级淫片免费看 | 国产自在线 | 9999视频| 美国一级黄色毛片 | 午夜天堂在线视频 | 欧美国产永久免费看片 | 成人午夜在线免费观看 | 性欧美大战久久久久久久免费观看 | 91久久久国产精品 | 在线播放亚洲精品 | a级在线 | 亚洲网站在线播放 | 羞羞答答视频 | 777zyz色资源站在线观看 |