`

com.sun.mail.smtp Description

    博客分类:
  • JMS
阅读更多
An SMTP protocol provider for the JavaMail API that provides access to an SMTP server. Refer to RFC 821 for more information.

The SMTP provider also supports ESMTP (RFC 1651). It can optionally use SMTP Authentication (RFC 2554) using the LOGIN, PLAIN, and DIGEST-MD5 mechanisms (RFC 2592 and RFC 2831).

To use SMTP authentication you'll need to provide the SMTP Transport with a username and password when connecting to the SMTP server. You can do this using one of the following approaches:
  


Provide an Authenticator object when creating your mail Session and provide the username and password information during the Authenticator callback.
Note that the mail.smtp.user property can be set to provide a default username for the callback, but the password will still need to be supplied explicitly.

This approach allows you to use the static Transport send method to send messages.


Call the Transport connect method explicitly with username and password arguments.
This approach requires you to explicitly manage a Transport object and use the Transport sendMessage method to send the message. The transport.java demo program demonstrates how to manage a Transport object. The following is roughly equivalent to the static Transport send method, but supplies the needed username and password:


Transport tr = session.getTransport("smtp");
tr.connect(smtphost, username, password);
msg.saveChanges(); // don't forget this
tr.sendMessage(msg, msg.getAllRecipients());
tr.close();

You'll also need to supply an appropriate realm when using DIGEST-MD5 authentication; your mail server administrator can supply this information. You can set this using the mail.smtp.saslrealm property, or the setSASLRealm method on SMTPTransport.

SMTP can also optionally request Delivery Status Notifications (RFC 1891). The delivery status will typically be reported using a "multipart/report" (RFC 1892) message type with a "message/delivery-status" (RFC 1894) part. JavaMail does not currently provide direct support for these new MIME types, but you can process them as any other "multipart" or "message" content, using MimeMultipart and MimeMessage objects.

See below for the properties to enable these features.

Note also that THERE IS NOT SUFFICIENT DOCUMENTATION HERE TO USE THESE FEATURES!!! You will need to read the appropriate RFCs mentioned above to understand what these features do and how to use them. Don't just start setting properties and then complain to us when it doesn't work like you expect it to work. READ THE RFCs FIRST!!!

The SMTP protocol provider supports the following properties, which may be set in the JavaMail Session object. The properties are always set as strings; the Type column describes how the string is interpreted. For example, use

props.put("mail.smtp.port", "888");

to set the mail.smtp.port property, which is of type int.
Name Type Description
mail.smtp.user String Default user name for SMTP.
mail.smtp.host String The SMTP server to connect to.
mail.smtp.port int The SMTP server port to connect to, if the connect() method doesn't explicitly specify one. Defaults to 25.
mail.smtp.connectiontimeout int Socket connection timeout value in milliseconds. Default is infinite timeout.
mail.smtp.timeout int Socket I/O timeout value in milliseconds. Default is infinite timeout.
mail.smtp.from String Email address to use for SMTP MAIL command. This sets the envelope return address. Defaults to msg.getFrom() or InternetAddress.getLocalAddress(). NOTE: mail.smtp.user was previously used for this. 
mail.smtp.localhost String Local host name. Defaults to InetAddress.getLocalHost().getHostName(). Should not normally need to be set if your JDK and your name service are configured properly. 
mail.smtp.ehlo boolean If false, do not attempt to sign on with the EHLO command. Defaults to true. Normally failure of the EHLO command will fallback to the HELO command; this property exists only for servers that don't fail EHLO properly or don't implement EHLO properly. 
mail.smtp.auth boolean If true, attempt to authenticate the user using the AUTH command. Defaults to false.
mail.smtp.dsn.notify String The NOTIFY option to the RCPT command. Either NEVER, or some combination of SUCCESS, FAILURE, and DELAY (separated by commas).
mail.smtp.dsn.ret String The RET option to the MAIL command. Either FULL or HDRS.
mail.smtp.allow8bitmime boolean If set to true, and the server supports the 8BITMIME extension, text parts of messages that use the "quoted-printable" or "base64" encodings are converted to use "8bit" encoding if they follow the RFC2045 rules for 8bit text. 
mail.smtp.sendpartial boolean If set to true, and a message has some valid and some invalid addresses, send the message anyway, reporting the partial failure with a SendFailedException. If set to false (the default), the message is not sent to any of the recipients if there is an invalid recipient address. 
mail.smtp.saslrealm String The realm to use with DIGEST-MD5 authentication.
mail.smtp.quitwait boolean If set to true, causes the transport to wait for the response to the QUIT command. If set to false (the default), the QUIT command is sent and the connection is immediately closed. (NOTE: The default may change in the next release.) 


In general, applications should not need to use the classes in this package directly. Instead, they should use the APIs defined by javax.mail package (and subpackages). Applications should never construct instances of SMTPTransport directly. Instead, they should use the Session method getTransport to acquire an appropriate Transport object.

* Reference brought to you by Bugzero, it's more than just bug tracking software!
分享到:
评论

相关推荐

    com.sun.pdfview.PDFRenderer

    import com.sun.pdfview.FullScreenWindow;import com.sun.pdfview.OutlineNode;import com.sun.pdfview.PDFDestination;import com.sun.pdfview.PDFFile;import com.sun.pdfview.PDFObject;import ...

    com.sun.rowset.jar.zip

    《com.sun.rowset.jar.zip——探索Sun公司的RowSet技术在数据库操作中的魅力》 在Java世界里,数据访问是核心任务之一,而Sun公司的RowSet技术则是Java数据库连接(JDBC)的重要组成部分,它为开发者提供了高效、...

    com.sun.jndi.ldap.jar

    《com.sun.jndi.ldap.jar:Maven中的 LDAP 相关库解析》 在Java开发中,`com.sun.jndi.ldap.jar`是一个重要的库文件,它包含了Java Naming and Directory Interface (JNDI) 的 LDAP(Lightweight Directory Access ...

    com.sun.media.jai等文件转换jar

    主页:http://java.sun.com/javase/6/docs/technotes/guides/imageio/index.html JAI 中的 Image I/O Tools,支持更多图片类型,例如JPEG-LS, JPEG2000, 和 TIFF。 主页:https://jai-imageio.dev.java.net/。JAI ...

    com.sun.jna 3.0.9

    2. **JNA的结构**:JNA库包括了`com.sun.jna`和`com.sun.jna.ptr`两个主要包,分别提供了基本的类型映射和指针操作。 3. **类型映射**:JNA自动将Java类型映射到对应的本地类型,如Java的`int`映射到C的`int`,`...

    com.sun.xfile包

    com.sun.xfile包 下载 ,另备注下找比较少使用包地址mavenhub.com

    com.sun.jna.examples

    《com.sun.jna.examples》是Java Native Access (JNA) 库的一个重要组成部分,它包含了丰富的示例代码,用于帮助开发者理解和使用JNA技术。JNA是Java平台上的一个开源库,它允许Java代码直接调用本地(操作系统级别...

    com.sun.crypto.provider.SunJCE

    【标题】"com.sun.crypto.provider.SunJCE" 是Java加密技术中一个关键的组件,它属于Oracle JDK的内置安全提供者。这个组件在描述中提到的问题是关于类`com.sun.crypto.provider.SunJCE`的加载问题,该类在某些特定...

    com.sun.crypto.provider.SunJCE----jar包

    在Java编程环境中,有时我们需要处理加密和解密操作,这时会用到`com.sun.crypto.provider.SunJCE`。这个类是Java加密扩展(Java Cryptography Extension, JCE)的一部分,由Sun Microsystems(现已被Oracle收购)...

    com.sun.jdmk.jmxtools.1.2.1 jmxtools-1.2.1.jar 亲测可用

    缺少jar包 Description Resource Path Location Type Missing artifact com.sun.jdmk:jmxtools:jar:1.2.1 pom.xml Maven Dependency Problem jmxtools-1.2.1.jar

    com.sun.net.httpserver.http.jar

    com.sun.net.httpserver

    com.sun.net.ssl.jar

    《深入理解Java SSL机制:以`com.sun.net.ssl.jar`为入口》 在Java平台中,安全套接层(SSL,Secure Sockets Layer)及其后续的传输层安全(TLS,Transport Layer Security)协议是实现网络通信加密的重要工具,...

    rt.jar(com.sun.*软件开发包)

    例如:com.sun.image.codec.jpeg等。com.sun.*, sun.* 开头的包都是 JRE 的底层类库,未被归档化。引入jar包只是规避了过期和受限的API。直接引用即可,但不建议长期使用。例如您正在导入工程文件启动报错,此时引用...

    亲测可用 com.sun.jmx. jmxri-1.2.1.jar

    Description Resource Path Location Type Missing artifact com.sun.jmx:jmxri:jar:1.2.1 pom.xml /eshop-storm line 2 Maven Dependency Problem

    加密解密字符串找不到 com.sun.crypto.provider.SunJCE

    Java加密解密字符串找不到 com.sun.crypto.provider.SunJCE() 用到jar包

    tesseract识别中文的com.sun.media.imageio.plugins.tiff.TIFFImageWriteParam下载

    OCR(Optical Character Recognition,光学字符识别)技术是将图像中的文本转换为机器可读格式的关键工具,而`com.sun.media.imageio.plugins.tiff.TIFFImageWriteParam`则是Java中处理TIFF图像格式时的一个关键类,...

    jakarta.mail-1.6.7-API文档-中文版.zip

    对应Maven信息:groupId:com.sun.mail,artifactId:jakarta.mail,version:1.6.7 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中的代码和结构保持不变...

    com.sun.jna

    从maven中得到的jna.jar里面没有examples的类(坑了我)。所以找到了一个examples包下面不是空的jna.jar.

    JAVA HTTP 发送 接收 com.sun.net.httpserver包 demo

    在Java中,我们可以使用多种库来实现HTTP通信,其中包括`com.sun.net.httpserver`包,这是一个内置的轻量级HTTP服务器,适用于测试、原型设计以及简单的应用。本示例将详细介绍如何使用`com.sun.net.httpserver`包...

Global site tag (gtag.js) - Google Analytics