Java Gmail smtp、Blackberry、BB、socketConnection、通过Gmail smtp以编程方式发送电子邮件

Java Gmail smtp、Blackberry、BB、socketConnection、通过Gmail smtp以编程方式发送电子邮件,java,ssl,blackberry,smtp,gmail,Java,Ssl,Blackberry,Smtp,Gmail,有人可以帮助我如何通过socketConnection以编程方式使用gmail smtp服务器。我的问题是如何编写TSL/SSL身份验证,因为我无法与服务器通信??有人在黑莓上用java做的 多谢各位 AlexJava中有一个用于发送邮件的库,名为。我不知道它是否可以与Blackberry一起使用,但如果后者是这样的话,就使用这个类: import javax.mail.*; import javax.mail.internet.InternetAddress; import javax.mai

有人可以帮助我如何通过socketConnection以编程方式使用gmail smtp服务器。我的问题是如何编写TSL/SSL身份验证,因为我无法与服务器通信??有人在黑莓上用java做的

多谢各位


Alex

Java中有一个用于发送邮件的库,名为。我不知道它是否可以与Blackberry一起使用,但如果后者是这样的话,就使用这个类:

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("your@email.at.gmail", "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);
    }
}
import javax.mail.*;
导入javax.mail.internet.InternetAddress;
导入javax.mail.internet.mimessage;
导入java.util.Properties;
公共类邮件{
私有MailUtils(){
}
公共静态void sendsmlMessage(字符串收件人[],字符串主题,
字符串消息,字符串来自)抛出MessaginException{
布尔调试=真;
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”);
put(“mail.smtp.socketFactory.class”、“javax.net.ssl.SSLSocketFactory”);
props.put(“mail.smtp.socketFactory.fallback”、“false”);
Session Session=Session.getDefaultInstance(props,
新的javax.mail.Authenticator(){
受保护的密码身份验证getPasswordAuthentication(){
返回新密码身份验证(“your@email.at.gmail“,“您的密码”);
}
}
);
setDebug(debug);
Message msg=新的mimessage(会话);
InternetAddress addressFrom=新的InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[]addressTo=新的InternetAddress[recipients.length];
for(int i=0;i
黑莓的开源电子邮件客户端怎么样。使用gmail的smtp服务器和handle的TSL/SSL身份验证没有问题

它恰好是RIM尚未发现的黑莓最流行的开源电子邮件客户端

这是一个页面,您可以从中下载并试用,或获取所有源代码:

这在BlackBerry上不起作用-那些javax.mail.*类在J2ME中不可用。好的,很抱歉。你想让我删除我的答案吗?Martc Novakowski说得对,我试了所有我想到的。。。我在NetOne解决方案中看到过,但我不确定它是否会起作用,而且有点贵。嗨,Vernom,谢谢你的回复,但我必须通过smpt(应用程序不是电子邮件客户端)在我的应用程序中以编程方式发送电子邮件,这就是开源的全部意义。LogicMail完成了您尝试执行的所有操作,您可以查看其源代码。基本上有两个问题需要解决:打开SSL网络连接和使用SMTP协议。许可证呢?我可以在非开源项目中使用它吗?我读过关于BSD许可证的内容,但我不清楚是否可以在封闭源代码项目中使用