title: Java Mail using office365 account
body: <p>Following is the error trace </p>
  
  <pre><code>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(&lt;generated&gt;)
      at com.hltcapital.virtualsecretaryapi.DemoApplication$$EnhancerBySpringCGLIB$$256155c4$$FastClassBySpringCGLIB$$ad34c0c5.invoke(&lt;generated&gt;)
      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(&lt;generated&gt;)
      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(&lt;generated&gt;)
      at com.hltcapital.virtualsecretaryapi.DemoApplication.localContainerEntityManagerFactoryBean(DemoApplication.java:76)
      at com.hltcapital.virtualsecretaryapi.DemoApplication$$EnhancerBySpringCGLIB$$256155c4.CGLIB$localContainerEntityManagerFactoryBean$1(&lt;generated&gt;)
      at com.hltcapital.virtualsecretaryapi.DemoApplication$$EnhancerBySpringCGLIB$$256155c4$$FastClassBySpringCGLIB$$ad34c0c5.invoke(&lt;generated&gt;)
      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(&lt;generated&gt;)
      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
  </code></pre>
  
  <p>I am trying to send the email using java spring boot email, 
  Below are the code blocks for the same.</p>
  
  <p>1) Configuration File</p>
  
  <pre><code>@Configuration
  public class EmailSendConfiguration{
  
  @Bean
  public JavaMailSender getJavaMailSender() {
      JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
      mailSender.setHost("m.outlook.com");
      mailSender.setPort(587);
  
      mailSender.setUsername("zzzz@company.com");
      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;
  }
  
  }
  </code></pre>
  
  <p>2) File which is used to send email</p>
  
  <pre><code>@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);
  }
  }
  </code></pre>
  
  <p>Can anyone please let me know the source of error?</p>