Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在“发送邮件”中添加标题,如“类似”;堆栈溢出<;不要-reply@stackoverflow.email&燃气轮机&引用;_Java_Spring Boot_Jakarta Mail - Fatal编程技术网

Java 在“发送邮件”中添加标题,如“类似”;堆栈溢出<;不要-reply@stackoverflow.email&燃气轮机&引用;

Java 在“发送邮件”中添加标题,如“类似”;堆栈溢出<;不要-reply@stackoverflow.email&燃气轮机&引用;,java,spring-boot,jakarta-mail,Java,Spring Boot,Jakarta Mail,我无法通过“从”选项卡向添加标题发送邮件。 我需要在邮件中添加标题和文本,如“堆栈溢出”” 如何添加邮件id的堆栈溢出标题字体 我的代码在添加下面的代码 String to = "rabin.samanta@xxx.com"; String from = "rabin.samanta@xxx.com"; Properties props = new Properties(); prop

我无法通过“从”选项卡向添加标题发送邮件。 我需要在邮件中添加标题和文本,如“堆栈溢出”” 如何添加邮件id的堆栈溢出标题字体

我的代码在添加下面的代码

            String to = "rabin.samanta@xxx.com";
        String from = "rabin.samanta@xxx.com";
        Properties props = new Properties();
        props.put("mail.smtp.host", "smtp-mail.outlook.com");
        props.put("mail.smtp.port", "587");
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.smtp.auth", "true");
        Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication("username", "password");
            }
        });
        String msgBody = "test............";
        Message msg = new MimeMessage(session);
        msg.setFrom(new InternetAddress(from, "NoReply"));
        msg.addRecipient(Message.RecipientType.TO, new InternetAddress(to, "Mr. Recipient"));
        msg.setSubject("Welcome To Java Mail API");
        msg.setText(msgBody);
        msg.setHeader("header_name", "header_value");
        Transport.send(msg);
        System.out.println("Email sent successfully...");
    }

您只需使用
String from=“Rabin Samanta”

InternetAddress
类文档

此类表示使用RFC822语法的Internet电子邮件地址。典型的地址语法形式为“user@host.domain或“个人姓名”


当你尝试这个时会发生什么

public static void main(String... args) throws Exception {
    Properties props = new Properties();
    props.put("mail.debug", "true");
    props.put("mail.smtp.host", "mail.smtpbucket.com");
    props.put("mail.smtp.port", "8025");
    props.put("mail.smtp.starttls.enable", "false");
    props.put("mail.smtp.auth", "false");

    JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
    javaMailSender.setJavaMailProperties(props);

    MimeMessage msg1 = javaMailSender.createMimeMessage();
    MimeMessageHelper msg = new MimeMessageHelper(msg1, true);
    String from= "Me <me@example.com>";
    msg.setFrom(new InternetAddress(from));
    msg.setTo("Me <me@example.com>");
    msg.setText("Hello");

    javaMailSender.send(msg1);
}
publicstaticvoidmain(String…args)引发异常{
Properties props=新属性();
props.put(“mail.debug”,“true”);
put(“mail.smtp.host”、“mail.smtpbucket.com”);
props.put(“mail.smtp.port”,“8025”);
props.put(“mail.smtp.starttls.enable”、“false”);
props.put(“mail.smtp.auth”、“false”);
JavaMailSenderImpl javaMailSender=新的JavaMailSenderImpl();
setJavaMailProperties(props);

MimeMessage msg1=javamailssender.createMimeMessage(); MimeMessageHelper msg=新的MimeMessageHelper(msg1,true); 字符串from=“Me”; msg.setFrom(新因特网地址(from)); msg.setTo(“我”); msg.setText(“你好”); javamailssender.send(msg1); }

并检查SMTP Bucket

MimeMessage msg1=javamailssender.createMimeMessage();MimeMessageHelper msg=新的MimeMessageHelper(msg1,true);字符串from=“test”;msg.setFrom(新因特网地址(from));msg.setTo(“拉宾。samanta@xx.com"); msg.setText(“你好”);javamailssender.send(msg1);