gpt4 book ai didi

java - 使用 Javamail 从 hotmail 发送邮件?

转载 作者:行者123 更新时间:2023-12-01 15:33:10 28 4
gpt4 key购买 nike

我可以从 Yahoo 和 Gmail 发送,但无论我做什么,我都无法从 hotmail 发送。

public class LiveSenderActivity extends javax.mail.Authenticator {
private String mailhost = "smtp.live.com";
private String user;
private String password;
private Session session;

static {
Security.addProvider(new com.provider.JSSEProvider());
}

public LiveSenderActivity(String user, String password) {
this.user = user;
this.password = password;

// This connects to the actual mailserver
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", mailhost);
props.put("mail.smtp.port", "587");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.auth", "true");

props.put("mail.smtp.socketFactory.port", "587");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.quitwait", "false");

session = Session.getDefaultInstance(props, this);
}

我尝试过使用或不使用 SSL 内容,以及使用端口 25 而不是 587...什么都没有。

我做错了什么吗?就像我说的,yahoo 和 gmail 很有魅力,但不是这个..

它也没有给我任何错误..

最佳答案

this JavaMail FAQ entry有帮助吗?

JavaMail 1.4 is capable of sending and reading messages using Hotmail. All that's required is to properly configure JavaMail. I'll illustrate the proper configuration using the demo programs that come with JavaMail - msgshow.java and smtpsend.java.

Let's assume your Hotmail username is "user@hotmail.com" and your password is "passwd".

To read mail from your Hotmail Inbox, invoke msgshow as follows:

java msgshow -D -T pop3s -H pop3.live.com -U user@hotmail.com -P passwd

By reading the msgshow.java source code, you can see how these command line arguments are used in the JavaMail API. You should first try using msgshow as shown above, and once that's working move on to writing and configuring your own program to use Hotmail. The code fragment shown above for connecting to Gmail will also work for connecting to Hotmail by simply changing the host name.

To send a message through Hotmail, invoke smtpsend as follows:

java -Dmail.smtp.starttls.enable=true -Dmail.smtp.port=587 smtpsend
-d -M smtp.live.com -U user@hotmail.com -P passwd
-A someotheruser@hotmail.com

(Note that I split the command over three lines for display, but you should type it on one line.)

The smtpsend program uses the System properties when creating the JavaMail Session, so the properties set on the command line will be available to the JavaMail Session.

The smtpsend program will prompt for a subject and message body text. End the message body with ^D on UNIX or ^Z on Windows.

Again, you can read the smtpsend.java source code to see how the command line arguments are used in the JavaMail API. The code fragment shown above for connecting to Gmail will also work for connecting to Hotmail by simply changing the host name and changing the connect call to t.connect(host, 587, username, password). There is, of course, more than one way to use the JavaMail API to accomplish the same goal. This should help you understand the essential configuration parameters necessary to use Hotmail.

关于java - 使用 Javamail 从 hotmail 发送邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9317210/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com