5

How to resolve exception error in processing. The server response was: 5.7.3 STA...

 2 years ago
source link: https://www.codeproject.com/Questions/5317024/How-to-resolve-exception-error-in-processing-The-s
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
How to resolve exception error in processing. The server response was: 5.7.3 STARTTLS is required to send mail [MR2P264CA0029.FRAP264.PROD.OUTLOOK.COM] while sending mail in C#?

I am getting below exception

Copy Code
 while sending mail in c#
 Error in processing. The server response was: 5.7.3 STARTTLS is required to send mail [MR2P264CA0029.FRAP264.PROD.OUTLOOK.COM]

What I have tried:

Code used to send mail updated as below:
web.config
<pre>  <add key="AdminEmail" value="[email protected]"/>
    <add key="SMTPServer" value="smtp.office365.com"/>
    <add key="SMTPServerPort" value="587"/>
Expand ▼   Copy Code
MailMessage objMailMsg = new MailMessage();
               MailAddress fromAddress = new MailAddress(Common.FromMail);
               SmtpClient smtpClient = new SmtpClient();

               int port = Common.SMTPPort;
               string FileName = Common.EMAIL_FILE_PATH+objEmail.AttachedFileName;
               string IPaddr = Common.SMTPServer;
               objMailMsg.From = fromAddress;

               string[] Toarray = objEmail.ToEmailId.Split(',');
               foreach (string ToAddress in Toarray)
               {
                   if (ToAddress.Trim() != string.Empty)
                       objMailMsg.To.Add(ToAddress.Trim());
               }
               if (objEmail.CCEmailId != null && objEmail.CCEmailId.Length > 0)
               {
                   string[] Ccarray = objEmail.CCEmailId.Split(',');
                   foreach (string CcAddress in Ccarray)
                   {
                       if(CcAddress.Trim()!= string.Empty)
                           objMailMsg.CC.Add(CcAddress.Trim());
                   }
               }

               char[] chrDelim = new char[] { ',' };

               foreach (string strSubstr in FileName.Split(chrDelim))
               {
                   if (File.Exists(strSubstr))
                   {
                       Attachment objAttachment = new Attachment(strSubstr);
                       objMailMsg.Attachments.Add(objAttachment);
                   }
               }
               objMailMsg.Subject = objEmail.EmailSubject;
               objMailMsg.Body = objEmail.EmailBody;
               objMailMsg.IsBodyHtml = true;
               if (port == 0)
               {
                   port = 25;

               }
               Common.WriteDDSLog("Email Sent :-"+FileName);
               smtpClient.Port = port;
               smtpClient.Host = IPaddr;
               smtpClient.Send(objMailMsg);

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK