简体   繁体   中英

Symfony Mailer Exchange mail server

Today I'm trying to connect my Symfony application to a local mail server that running as Microsoft Exchange server.

First, before switching to Symfony my web project was developed with Asp.NET, for some personal reasons I refund the project under Symfony.

In C# this code was working correctly :

public static void MailSender(string server, string fromDisplayName, string fromMailAddress, List<List<KeyValuePair<string,string>>> tos, string subject, string body, List<string> attachments = null, List<List<KeyValuePair<string,string>>> ccs = null, List<List<KeyValuePair<string,string>>> bccs = null)
    {
        using (MailMessage mailMessage = new MailMessage())
        {
            mailMessage.From = new MailAddress(fromMailAddress, fromDisplayName);
            foreach(List<KeyValuePair<string, string>> to in tos){
                mailMessage.To.Add(new MailAddress(to[1].Value.ToString(), to[0].Value.ToString()));
            }
            if (ccs != null){
                foreach(List<KeyValuePair<string, string>> cc in ccs){
                    mailMessage.CC.Add(new MailAddress(cc[1].Value.ToString(), cc[0].Value.ToString()));
                }
            }
            if (bccs != null){
                foreach(List<KeyValuePair<string, string>> bcc in bccs){
                    mailMessage.CC.Add(new MailAddress(bcc[1].Value.ToString(), bcc[0].Value.ToString()));
                }
            }
            mailMessage.Subject = subject;
            mailMessage.Body = body;
            mailMessage.IsBodyHtml = true;
            if (attachments != null)
            {
                foreach (string attachment in attachments)
                    mailMessage.Attachments.Add(new Attachment(attachment));
            }

            using (SmtpClient smtpClient = new SmtpClient(server))
            {
                smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
                smtpClient.UseDefaultCredentials = true;
                smtpClient.Send(mailMessage);
            }
        }
    }

The server url was in the format: myserver.domain.tld . Also it used the Windows Integrated Authentication.

How can I configure PHP or Symfony (or both) to work with my local Exchange mail server ?

I tried to use this type of url in MAILER_DSN variable: smtp://user:pass@myserver.domain.tld (user as email address with '%40' for '@' character.

Thanks.

Sorry for this question cause Its a mistake from me, I put MAILER_DSN=smtp://server.tld:25

Also, I commented a line into config/packages/messenger.yaml this line: Symfony\Component\Mailer\Messenger\SendEmailMessage: async

This second option solve my problem.

If you had another option, I'm aware about it!

Thks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM