JavaMail with MS Exchange: No authentication mechansims supported by both server and client

前端 未结 6 2147
天命终不由人
天命终不由人 2021-01-12 01:39

I\'ve been trying for days now to send mail from Grails application and unsuccessfully. I\'m using:

  • grails 1.3.7
  • mail 1.0 plugin
  • spring-secur
6条回答
  •  难免孤独
    2021-01-12 02:19

    Here's my solution, maybe it's not the best way, but it works for me...

    in the mail-config.xml:

    
        
        
        
        
        
        
        
        
            
                ${mail.auth}
            
        
    
    

    and here's the setting:

    mail.from=XXX Team 
    mail.host=exchange.xxx.com
    mail.port=25
    mail.protocol=smtp
    mail.auth=false
    mail.username=
    mail.password=
    

    and finally, the code:

    package com.xxx.service;
    import org.springframework.mail.javamail.JavaMailSenderImpl;
    
    public class MailSender extends JavaMailSenderImpl {
    
        private boolean authRequired;
    
        @Override
        public String getUsername() {
            if (!authRequired) {
                return null;
            }
            return super.getUsername();
        }
    
        @Override
        public String getPassword() {
            if (!authRequired) {
                return null;
            }
            return super.getPassword();
        }
    
        public boolean isAuthRequired() {
            return authRequired;
        }
    
        public void setAuthRequired(boolean authRequired) {
            this.authRequired = authRequired;
        }
    
    }
    

提交回复
热议问题