web-dev-qa-db-fra.com

Java Mail utilisant un compte office365

Voici la trace d'erreur

554 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 16.55847:7B140000,  4.30158:DC040000 [Hostname=MWHPR22MB0815.namprd22.prod.Outlook.com]
DEBUG SMTP: got response code 554, with response: 554 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 16.55847:7B140000, 4.30158:DC040000 [Hostname=MWHPR22MB0815.namprd22.prod.Outlook.com]

RSET
250 2.0.0 Resetting
DEBUG SMTP: MessagingException while sending, THROW: 
com.Sun.mail.smtp.SMTPSendFailedException: 554 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 16.55847:7B140000, 4.30158:DC040000 [Hostname=MWHPR22MB0815.namprd22.prod.Outlook.com]

    at com.Sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.Java:2358)
    at com.Sun.mail.smtp.SMTPTransport.finishData(SMTPTransport.Java:2110)
    at com.Sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.Java:1316)
    at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.Java:462)
    at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.Java:321)
    at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.Java:310)
    at com.hltcapital.virtualsecretaryapi.core.JavaEmailService.sendSimpleMessage(JavaEmailService.Java:22)
    at com.hltcapital.virtualsecretaryapi.DemoApplication.dataSource(DemoApplication.Java:57)
    at com.hltcapital.virtualsecretaryapi.DemoApplication$$EnhancerBySpringCGLIB$$256155c4.CGLIB$dataSource$0(<generated>)
    at com.hltcapital.virtualsecretaryapi.DemoApplication$$EnhancerBySpringCGLIB$$256155c4$$FastClassBySpringCGLIB$$ad34c0c5.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.Java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.Java:361)
    at com.hltcapital.virtualsecretaryapi.DemoApplication$$EnhancerBySpringCGLIB$$256155c4.dataSource(<generated>)
    at Java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at Java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62)
    at Java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
    at Java.base/Java.lang.reflect.Method.invoke(Method.Java:564)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.Java:154)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.Java:582)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.Java:1247)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.Java:1096)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:535)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:495)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.Java:317)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:315)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:199)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.resolveBeanReference(ConfigurationClassEnhancer.Java:392)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.Java:364)
    at com.hltcapital.virtualsecretaryapi.DemoApplication$$EnhancerBySpringCGLIB$$256155c4.dataSource(<generated>)
    at com.hltcapital.virtualsecretaryapi.DemoApplication.localContainerEntityManagerFactoryBean(DemoApplication.Java:76)
    at com.hltcapital.virtualsecretaryapi.DemoApplication$$EnhancerBySpringCGLIB$$256155c4.CGLIB$localContainerEntityManagerFactoryBean$1(<generated>)
    at com.hltcapital.virtualsecretaryapi.DemoApplication$$EnhancerBySpringCGLIB$$256155c4$$FastClassBySpringCGLIB$$ad34c0c5.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.Java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.Java:361)
    at com.hltcapital.virtualsecretaryapi.DemoApplication$$EnhancerBySpringCGLIB$$256155c4.localContainerEntityManagerFactoryBean(<generated>)
    at Java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at Java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62)
    at Java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
    at Java.base/Java.lang.reflect.Method.invoke(Method.Java:564)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.Java:154)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.Java:582)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.Java:1247)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.Java:1096)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:535)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:495)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.Java:317)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:315)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:199)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.Java:1089)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.Java:859)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.Java:550)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.Java:140)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.Java:762)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.Java:398)
    at org.springframework.boot.SpringApplication.run(SpringApplication.Java:330)
    at org.springframework.boot.SpringApplication.run(SpringApplication.Java:1258)
    at org.springframework.boot.SpringApplication.run(SpringApplication.Java:1246)
    at com.hltcapital.virtualsecretaryapi.DemoApplication.main(DemoApplication.Java:111)
    at Java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at Java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62)
    at Java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
    at Java.base/Java.lang.reflect.Method.invoke(Method.Java:564)
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.Java:48)
    at org.springframework.boot.loader.Launcher.launch(Launcher.Java:87)
    at org.springframework.boot.loader.Launcher.launch(Launcher.Java:50)
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.Java:51)
QUIT
221 2.0.0 Service closing transmission channel

J'essaie d'envoyer l'e-mail en utilisant Java email de démarrage de printemps, voici les blocs de code pour le même.

1) Fichier de configuration

@Configuration
public class EmailSendConfiguration{

@Bean
public JavaMailSender getJavaMailSender() {
    JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
    mailSender.setHost("m.Outlook.com");
    mailSender.setPort(587);

    mailSender.setUsername("[email protected]");
    mailSender.setPassword("password");

    Properties props = mailSender.getJavaMailProperties();
    props.put("mail.transport.protocol", "smtp");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.debug", "true");

    return mailSender;
}

}

2) Fichier utilisé pour envoyer des e-mails

@Service
public class JavaEmailService{

@Autowired
public JavaMailSender emailSender;

public void sendSimpleMessage(String to, String subject, String text) {

    SimpleMailMessage message = new SimpleMailMessage(); 
    message.setTo(to); 
    message.setSubject(subject); 
    message.setText(text);
    EmailSendConfiguration esc = new EmailSendConfiguration();
    esc.getJavaMailSender().send(message);
}
}

Quelqu'un peut-il me faire savoir la source de l'erreur?

5
Vishrut Patel

J'ai eu le même problème. J'ajoute set pour résoudre le problème.

SimpleMailMessage msg = new SimpleMailMessage();
msg.setTo("XXXXXXX", "XXXXXXXX");
msg.setFrom("XXXXXXXX"); // missed line
msg.setSubject("Testing from Spring Boot");
msg.setText("Hello World \n Spring Boot Email");
javaMailSender.send(msg);
0
Rajesh Narayanan