Not able to connect to smtp from Azure Cloud Service

守給你的承諾、 提交于 2020-02-06 09:37:48

问题


we are having 2 cloud services hosted on Azure.

Both the services depend on our smtp server for sending mails.

Problem is azure cloud service not able to connect to our smtp server.

we are able to use same code on internal machines without any issue. also we had checked that 25 port is open and IP address are also not on blacklist.

Below is the error while connecting from cloud service :

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 111.93.111.42:25

Email sending logic

MailMessage message = new MailMessage(senderID, reminder.UserName, template.Subject, body);
message.From = new MailAddress(data.SenderEmail, data.SenderName);
message.IsBodyHtml = true;

            try
            {
                SmtpClient smtp = new SmtpClient
                {
                    Host = data.SMTPServer, // smtp server address here...                    
                    Port = data.PortNo,
                    EnableSsl = data.SSL,
                    DeliveryMethod = SmtpDeliveryMethod.Network,
                    Credentials = new System.Net.NetworkCredential(senderID, senderPassword),
                    Timeout = 30000,
                };
                smtp.Send(message);
                //Thread th = new Thread(() => { smtp.Send(message); });
                //th.Start();

            }
            catch (Exception ex)
            {
                ErrorLogging.ErrorLog(ex, "Error Reminders send Mail - Employee Reminders Mail Error Message : " + ex.Message, "Employee Reminders Mail", "0", "EmployeeRemindersMail", schemaName, companyId);
            }

回答1:


Microsoft recommends that Azure customers employ authenticated SMTP relay services (typically connected via TCP port 587 or 443, but often support other ports too) to send e-mail from Azure VMs or from Azure App Services. These services specialize in sender reputation to minimize the possibility 3rd party e-mail providers will reject the message. Such SMTP relay services include but are not limited to SendGrid. It is also possible you have a secure SMTP relay service running on premises that can be used. Use of these e-mail delivery services is in no way restricted in Azure regardless of subscription type.

Reference: https://blogs.msdn.microsoft.com/mast/2017/11/15/enhanced-azure-security-for-sending-emails-november-2017-update/

You may also want to refer this thread which addresses similar issue and see if that helps.



来源:https://stackoverflow.com/questions/50059171/not-able-to-connect-to-smtp-from-azure-cloud-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!