有人可以帮助我如何使用gmail smtp服务器编程通过socketConnection。我的问题是我怎么写写一个TSL/SSL认证,因为我不能与服务器通信?有人从黑莓手机上的Java做到这一点?Gmail smtp,黑莓,BB,socketConnection,通过gmail发送电子邮件smtp编程
谢谢
亚历
有人可以帮助我如何使用gmail smtp服务器编程通过socketConnection。我的问题是我怎么写写一个TSL/SSL认证,因为我不能与服务器通信?有人从黑莓手机上的Java做到这一点?Gmail smtp,黑莓,BB,socketConnection,通过gmail发送电子邮件smtp编程
谢谢
亚历
怎么样一个开源电子邮件客户端的黑莓。使用gmail的smtp服务器和句柄的TSL/SSL认证没有问题没有问题。
它恰好是RIM尚未发现的黑莓最受欢迎的开源电子邮件客户端。
这里是一个页面,从中可以下载它,并尝试它,或得到所有的源代码。 http://www.logicprobe.org/proj/logicmail
有在Java中发送邮件一个lib,它叫做JavaMail。我不知道这是否可以与黑莓手机使用,但如果是后者的话,只需要使用这个类:
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;
public class MailUtils {
private MailUtils() {
}
public static void sendSSLMessage(String recipients[], String subject,
String message, String from) throws MessagingException {
boolean debug = true;
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.auth", "true");
props.put("mail.debug", "true");
props.put("mail.smtp.port", "465");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("[email protected]", "your password");
}
}
);
session.setDebug(debug);
Message msg = new MimeMessage(session);
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++) {
addressTo[i] = new InternetAddress(recipients[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
}
}
嗨Vernom,谢谢你的回复但我必须在我的应用程序中通过smpt以编程方式发送电子邮件(应用程序不是电子邮件客户端) – Alex 2010-03-25 19:51:56
这就是开源的全部要点。 LogicMail做你想做的一切,你可以看看它的源代码。基本上有两个问题需要解决:打开SSL网络连接并说SMTP协议。 – octo 2010-03-25 20:59:37
许可证怎么样?我可以在非开源项目中使用它吗?我阅读了BSD许可证,但不清楚我是否可以使用或不使用闭源项目 – Alex 2010-03-26 07:17:34