我如何发送电子邮件,而无需使用身份验证的Java [英] How i send email without authentication using java

查看:476
本文介绍了我如何发送电子邮件,而无需使用身份验证的Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用java发送电子邮件无需验证。
有人可以帮我吗?

I would like to send email without authentication using java. Can someone help me?

通过认证,我做如下:

    public void sendEmail() throws EmailException{
    SimpleEmail email = new SimpleEmail();
    email.setHostName("smtp.gmail.com");
    email.setSmtpPort(465);
    email.addTo("XXX@gmail.com", "XXXX");
    email.setFrom("XXXX@gmail.com","XXXXX");
    email.setSubject("testando . . .");
    email.setMsg("testando 1");
    email.setSSL(true);
    email.setAuthentication("xxxxxx@gmail.com", "XXXXX");
    email.send();
}

我忘了说,我没有一个供应商。我需要一个供应商最后,我emailFrom主题和消息,并需要发送这封电子邮件怎么样?

I forgot to say that i do not have a provider. i need an provider finally, i have emailFrom Subject and Message, and need send this email how?

推荐答案

如果它只是用于测试目的,您可以尝试的 Papercute 。虽然它的运行,剪纸会自动选择发送到任何IP地址的标准SMTP端口(25)的电子邮件。你只需从你的应用程序中发送邮件,并切换到剪纸对其进行审查。

If it is only for testing purposes, you may try Papercute. While it’s running, Papercut automatically picks up e-mail sent to the standard SMTP port (25) on any IP address. You just send mail from your application and switch to Papercut to review it.

import java.util.Date;
import java.util.Properties;

import javax.mail.Message.RecipientType;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class SendMail {

    public static void main(String[] args) throws Exception {
        Properties props = new Properties();
        props.put("mail.smtp.host", "127.0.0.1");
        props.put("mail.smtp.port", "25");
        props.put("mail.debug", "true");
        Session session = Session.getDefaultInstance(props);
        MimeMessage message = new MimeMessage(session);
        message.setFrom(new InternetAddress("admin@test.com"));
        message.setRecipient(RecipientType.TO, new InternetAddress("a@b.com"));
        message.setSubject("Notification");
        message.setText("Successful!", "UTF-8"); // as "text/plain"
        message.setSentDate(new Date());
        Transport.send(message);
    }

}

这篇关于我如何发送电子邮件,而无需使用身份验证的Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆