`

javaMail 邮件

    博客分类:
  • J2EE
阅读更多
  
SMTP POP3的区别到底是什么?
http://www.wisegeek.com/what-is-the-difference-between-smtp-and-pop.htm
引用
There are two standards currently used for most e-mail sent today. SMTP stands for simple mail transfer protocol. POP is an acronym Post Office Protocol. Though it may sound confusing, the difference is not hard to understand. POP is a protocol for storage of email. SMTP is a protocol for sending and receiving.
要站在邮件服务器的角度理解邮件协议:
对server来说,smtp就是用来收/发邮件的协议;而pop(3是其版本)是用来存储邮件的协议。


How email works (MTA, MDA, MUA):
http://en.kioskea.net/contents/courrier-electronique/fonctionnement-mta-mua.php3
引用
简而言之:
MTA(Mail Transport Agent) 就是常说的 SMTP Server
MDA(Mail Delivery Agent) 就是常说的 POP server or IMAP server (depending on which protocol is used.)
MUA(Mail User Agent) 就是常说的 email client(邮件客户端),如Mozilla Thunderbird, Microsoft Outlook, Lotus Notes等。




SMTP Server reply codes:
http://www.greenend.org.uk/rjk/tech/smtpreplies.html


Email Headers 详解:
http://support.google.com/mail/answer/29436?hl=en
headers 中的 From / Sender / Return-Path 的区别是什么?
http://stackoverflow.com/questions/3835065/smtp-e-mail-headers-return-path-vs-sender-vs-from



邮件反垃圾之 MX SPF DKIM DMARC:
http://m.udpwork.com/item/4690.html
MX (Mail eXchanger):
http://support.google.com/a/bin/answer.py?hl=cn&hlrm=zh-Hant&answer=48090
引用
邮件交换 (MX) 记录将域的电子邮件导向至服务器。一个域可定义多个 MX 记录,每个记录都有不同的优先级,数字越小表示优先级越高。如果邮件通过第一优先级记录无法递送,则采用第二优先级,以此类推。
DKIM (DomainKeys Identified Mail):
http://support.google.com/a/bin/answer.py?hl=cn&hlrm=en&answer=174124
引用
垃圾邮件发件人可以伪造邮件上的“发件人”地址,使垃圾邮件看起来好像来自某个受信任的其他的域、地址。为了防止这种滥用行为,使用 DKIM 技术可以将数字“签名”添加到从发件人所在域发送的邮件的 Email Headers 中。收件人可以通过检查域签名来验证该邮件是否确实来自于发件人所在的域,且中途没有被更改过。
SPF (Sender Policy Framework):
http://blog.csdn.net/blade2001/article/details/8509203
引用
SPF是为了防范垃圾邮件而提出来的一种DNS记录类型,它是一种TXT类型的记录,它用于登记某个域名拥有的用来外发邮件的所有IP地址。当你定义了你的domain name的SPF记录之后,接收邮件方会根据你的SPF记录来确定连接过来的IP地址是否被包含在SPF记录里面,如果在,则认为是一封正确的邮件,否则则认为是一封伪造的邮件。
DMARC (Domain-based Message Authentication, Reporting & Conformance)
http://blog.163.com/pandalove@126/blog/static/9800324520123147328334/ or
http://www.mail163.cn/anti-spam/DMARC-Technical.html
引用
由 Paypal,Google,Microsoft, Yahoo 等公司联手成立的,基于现有的 DKIM 和 SPF 两大主流电子邮件安全协议的反垃圾邮件技术,目前尚未成熟,仍处于草案阶段。




工具:
通过分析 Email Header,找到邮件最初被哪个 SMTP Server 发出来(它的域名及IP地址;在收件服务器对该原始发件SMTP Server做SPF时,会需要用到它的IP地址):
http://whatismyipaddress.com/trace-email




关于 gmail 的 mailed-by & signed-by:
http://blog.wordtothewise.com/2011/06/gmail-shows-authentication-data-to-the-recipient/



Java Mail


Session,Transport,(under Transport)Socket Connection 关系:
A Session only holds configuration information.
A Transport corresponds to a single connection.
https://forums.oracle.com/forums/thread.jspa?threadID=2435565
引用
You can definitely share a JavaMail Session object between threads since the Session contains
only configuration information.

Sharing a JavaMail Transport object between threads is not a good idea. A Transport represents
a connection to the mail server and only one thread can use the connection at a time.

If you open a Transport connection and keep it around for a long time without using it, the server
may close the connection. Servers want you to open connections only when you're using them.
Servers also don't want you to abuse a connection and so may close a connection if they think
you're using it too much (e.g., to send spam). You can't prevent either of these actions, but you
can detect that the connection has been closed and open a new connection when you need it.
http://stackoverflow.com/questions/14238149/whats-the-relation-between-session-and-smtp-connection-in-javamail


Session/Transport 与 Thread safety:
http://stackoverflow.com/questions/12732584/threadsafety-in-javamail
引用
Admittedly the thread safety rules for JavaMail are not well documented, but hopefully they mostly match what you would expect.
Multiple threads can use a Session.
Since a Transport represents a connection to a mail server, and only a single thread can use the connection at a time, a Transport will synchronize access from multiple threads to maintain thread safety, but you'll really only want to use it from a single thread.
Similarly, a Store can be used by multiple threads, but access to the underlying connection will be synchronized and single threaded.
A Message should only be modified by a single thread at a time, but multiple threads should be able to read a message safely (although it's not clear why you would want to do that).
https://forums.oracle.com/forums/thread.jspa?threadID=1587336&tstart=105
引用
First, don't use Session.getDefaultInstance, use Session.getInstance.
A Session encapsulates configuration information. You can safely shared
a Session between threads, assuming they all need the same configuration.

Sharing an SMTP Transport between threads is probably a bad idea.
While the Transport has synchronized methods to protect its own state,
you might not want one thread to wait until another thread is completely
done sending a message. It may depend on whether the main job of each
thread is to send a message, or whether the threads are doing lots of other
work and sending a message is just incidental and infrequent.



JavaMail Official Site:
http://www.oracle.com/technetwork/java/javamail/index.html
JAVAMAIL API FAQ:
http://www.oracle.com/technetwork/java/javamail/faq/index.html
JavaMail API Design Specification:
http://www.oracle.com/technetwork/java/javamail-1-149769.pdf
JavaMail API Javadocs:
http://javamail.kenai.com/nonav/javadocs/
Sending an Email using the JavaMail API:
http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/javamail/javamail.html
Fundamentals of the JavaMail API:
http://www.digilife.be/quickreferences/pt/fundamentals%20of%20the%20javamail%20api.pdf
JavaMail深入体验开发二: JavaMail的体系结构及发送复杂邮件:
http://blog.csdn.net/t12x3456/article/details/7636701
引用

JavaMail API按其功能划分通常可分为如下三大类:
创建和解析邮件内容的API :Message类是创建和解析邮件的核心API,它的实例对象代表一封电子邮件。
发送邮件的API:Transport类是发送邮件的核心API类,它的实例对象代表实现了某个邮件发送协议的邮件发送对象,例如SMTP协议。
接收邮件的API:Store类是接收邮件的核心API类,它的实例对象代表实现了某个邮件接收协议的邮件接收对象,例如POP3协议。
Session类
Session类用于定义整个应用程序所需的环境信息,以及收集客户端与邮件服务器建立网络连接的会话信息,如邮件服务器的主机名、端口号、采用的邮件发送和接收协议等。Session对象根据这些信息构建用于邮件收发的Transport和Store对象,以及为客户端创建Message对象时提供信息支持。
coderanch上的javamail相关资源:
http://www.coderanch.com/how-to/java/JavaEnterpriseEditionFaq



spring 的 javamail 封装:
http://static.springsource.org/spring/docs/current/spring-framework-reference/html/mail.html
AOP 101: Speeding up Spring’s JavaMailSenderImpl with AOP:
http://springinpractice.com/2008/11/15/aop-101-speeding-up-springs-javamailsenderimpl-with-aop/#



关于smtp发送的 mail.smtp.timeout 和 mail.smtp.connectiontimeout:
https://forums.oracle.com/forums/thread.jspa?messageID=6660679
引用
The java socket api makes a distinction between the timeout for opening a socket connection and the timeout for any read/write operation on that socket after it has been opened.
So mail.smtp.connectiontimeout is the timeout (in milliseconds) for establishing the SMTP connection and mail.smtp.timeout is the timeout (also milliseconds) for sending the mail messages. You can start by setting them both to the same reasonable value depending on how slow your servers tend to be and then tune them for the best user experience.
transport.close()时会用到mail.smtp.timeout。
这两个 timeout 的默认值都是无限大(Default is infinite timeout).



关于JavaMail v1.4.3+ 的 SMTPTransport.isConnected() 与 mail.smtp.noop.strict(noopStrict,默认true)的关系:
https://forums.oracle.com/forums/thread.jspa?threadID=1556610
引用
JavaMail uses the SMTP NOOP command to determine if the connection is still alive and surprisingly some servers don't return the correct response code to that command. We used to be very lax about the expected response code but as more and more servers started returning the expected response code we tightened this up. If you're using an older server that still returns the wrong response code, you might need to set "mail.smtp.noop.strict" to "false".



疑问:
prop配置的mail.from、mail.smtp.from,及MimeMessage本身的setFrom()之from的关系是什么?
为什么配置了mail.from或mail.smtp.from,MimeMessage本身还必须通过调用setFrom()设置from(不设置的话收件人收到的email message在收件箱里看不到from信息的)?
解答:
http://javamail.kenai.com/nonav/javadocs/com/sun/mail/smtp/SMTPMessage.html#setEnvelopeFrom(java.lang.String)
引用
Set the From address to appear in the SMTP envelope. Note that this is different than the From address that appears in the message itself. The envelope From address is typically used when reporting errors. See RFC 821 for details.
If set, overrides the mail.smtp.from property.
http://www.oracle.com/technetwork/java/faq-135477.html#smtpfrom
http://stackoverflow.com/questions/1782659/how-to-set-the-return-path-to-an-email-address-other-than-sender-address-using-j
message本身的from 和 mail.from/mail.smtp.from是完全不一样的;message本身的from是邮件的收件人看到的“邮件是由谁发的”;而mail.from/mail.smtp.from,则是邮件被退回(bounced)等时,被退到的邮箱地址。
另外注意message的replyTo是设置“回复地址”的;message的replyTo如果未设置,默认就使用其from;如果希望回复邮箱和发件邮箱不一样,可以设置该属性。
mail.xxx和mail.protocol.xxx之间,则是在该特定protocol下,后者会将前者重写掉的关系。
另外记得在prop里或者设置"mail.user" and "mail.host",或者设置"mail.from",不可以三个都不设置:
http://www.oracle.com/technetwork/java/faq-135477.html#securityManager
引用
Alternatively, the application can use its own Properties object and be sure to set the "mail.from" property or the "mail.user" and "mail.host" properties (see the InternetAddress.getLocalAddress() method).



connection hangs by SMTP Server:
http://stackoverflow.com/questions/8265933/continuous-email-server-connection-using-java-mail-api


use Spring + JNDI acquire javamail Session:
http://stackoverflow.com/questions/12257304/javamailsender-returning-null-pointer-exception
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics