Processing JavaMail 1.5.4无法发送邮件吗?
大家好,我一直在努力让这个工作,但它没有,我试着检查,如果所有的图书馆是最新的,我更新了他们,我确保我没有打字错误,我错过了什么?我知道在写email的地方我有“MYEMAIL”和类似的密码。这是我的密码:Processing JavaMail 1.5.4无法发送邮件吗?,processing,jakarta-mail,Processing,Jakarta Mail,大家好,我一直在努力让这个工作,但它没有,我试着检查,如果所有的图书馆是最新的,我更新了他们,我确保我没有打字错误,我错过了什么?我知道在写email的地方我有“MYEMAIL”和类似的密码。这是我的密码: // Daniel Shiffman // http://www.shiffman.net // Simple E-mail Checking // This code requires the Java mail library
// Daniel Shiffman
// http://www.shiffman.net
// Simple E-mail Checking
// This code requires the Java mail library
// smtp.jar, pop3.jar, mailapi.jar, imap.jar, activation.jar
// Download:// http://java.sun.com/products/javamail/
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
void setup() {
size(200,200);
// Function to check mail
// Function to send mail
sendMail();
noLoop();
}
public class Auth extends Authenticator {
public Auth() {
super();
}
public PasswordAuthentication getPasswordAuthentication() {
String username, password;
username = "MYEMAIL";
password = "MYPASSWORD";
System.out.println("authenticating. . ");
return new PasswordAuthentication(username, password);
}
}
// A function to send mail
void sendMail() {
// Create a session
String host="smtp.gmail.com";
Properties props=new Properties();
// SMTP Session
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", host);
props.put("mail.smtp.port", "25");
props.put("mail.smtp.auth", "true");
// We need TTLS, which gmail requires
props.put("mail.smtp.starttls.enable","true");
// Create a session
Session session = Session.getDefaultInstance(props, new Auth());
try
{
// Make a new message
MimeMessage message = new MimeMessage(session);
// Who is this message from
message.setFrom(new InternetAddress("MYEMAIL", "Name"));
// Who is this message to (we could do fancier things like make a list or add CC's)
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("MYEMAIL", false));
// Subject and body
message.setSubject("Hello World!");
message.setText("It's great to be here. . .");
// We can do more here, set the date, the headers, etc.
Transport.send(message);
println("Mail sent!");
}
catch(Exception e)
{
e.printStackTrace();
}
}
当我尝试运行代码时,我收到一个错误,表明我的连接超时:
原因:java.net.ConnectException:连接超时:java.net.DualStackPlainSocketImpl.connect0(本机方法)位于java.net.DualStackPlainSocketImpl.socketConnect(未知源)位于java.net.AbstractPlainSocketImpl.doConnect(未知源)位于java.net.AbstractPlainSocketImpl.connectToAddress(未知源)在java.net.socksocketimpl.connect(未知源代码)在java.net.PlainSocketImpl.connect(未知源代码)在java.net.Socket.connect(未知源代码)在java.net.Socket.connect(未知源代码)在com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:312)在java.net.net.Socket.SocketFetcher.connect(未知源代码)在java.com.sun.mail.util.SocketFetcher.com.com在com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:236)在com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2019)。。。还有12个
这将是交叉张贴在处理论坛的方式,我会添加链接,当我问的问题有 交叉发布:JavaMail常见问题解答已经发布。