title: ASP.NET Sending email via Exchange Server which server certificate is used?
body: <p>I am having issues sending email from an ASP.NET application.  I keep getting the error message:</p>
  <p>&quot;The remote certificate is invalid according to the validation procedure.&quot;</p>
  <p>Doing research here and on other sites, it seems the certificate being presented is not our public GoDaddy certificate which covers our external domain name when accessing the Exchange 2013 server from the internet side.</p>
  <p>Looking in the Exchange Admin centre on the mail server I can see various entries in the &quot;Certificates&quot; section:</p>
  <p>Microsoft Exchange Server Auth Certificate (assigned to SMTP)</p>
  <p>Microsoft Exchange (assigned to SMTP)</p>
  <p>Exchange Delegation Federation (assigned to SMTP, Federation)</p>
  <p>GoDaddy Cert (assigned to IMAP, POP, IIS, SMTP)</p>
  <p>Internal Transport (assigned to IMAP, POP, SMTP)</p>
  <p>(all the above certs are Self Signed except the GoDaddy one)</p>
  <p>When I send email via ASP.NET using System.NET.Mail which of the above certificates is being used.  I have tried using Port 25, 465 and 587 and all get the same error?</p>
  <p>Is there a way I can assign the GoDaddy cert to all the above entries and if I did would it break any of the internal email setup?</p>
  <p>Any Help Appreciated.</p>
  <p>Siv</p>
  <p>Addendum: email sending code:</p>
  <pre><code>    Private Sub CreatePatrolsEmail(ByRef p As Patrols)
  
      Dim mailto As New MailAddress(&quot;external@email.com&quot;)
      Dim mailfrom As New MailAddress(&quot;internal@domainname.co.uk&quot;)
      Dim message As New MailMessage(mailfrom, mailto), Msg As String = &quot;&quot;
      Dim mailClient As New SmtpClient()
      Dim UserAndPass As New NetworkCredential()
      Dim ReplyAddress As String = &quot;&quot;
      Dim Script = &quot;&quot;
      Dim n As Integer = 0
      Dim BodyText As String = &quot;&quot;
  
      Try
          message.Subject = &quot;Issue relating to &quot; &amp; p.IssueDescription &amp; &quot;.&quot;
  
          'Mail.SubjectEncoding = Text.Encoding.UTF8
  
          BodyText = &quot;This email is to bring to your attention the following issue:&quot; &amp; NNL
          BodyText += &quot;Building: &quot; &amp; p.Building &amp; NL
          BodyText += &quot;Location: &quot; &amp; p.Location &amp; NL
          BodyText += &quot;Issue:&quot; &amp; p.IssueDescription &amp; NL
          BodyText += &quot;Additional Information:&quot; &amp; NNL
          BodyText += p.AdditionalInfo &amp; NNL
          BodyText += &quot;Sent from the Logging System.&quot; &amp; NL
          BodyText += &quot;Date: &quot; &amp; Now.ToShortDateString &amp; NL
          BodyText += &quot;Time: &quot; &amp; Now.ToShortTimeString
  
          message.Body = BodyText
  
          'send the message
          mailClient = New SmtpClient(&quot;mail.domainname.co.uk&quot;, 587) 'specify the mail server address
          mailClient.EnableSsl = True
          mailClient.UseDefaultCredentials = False
          mailClient.Credentials = New Net.NetworkCredential(&quot;internal@domainname.co.uk&quot;, &quot;passwordtext&quot;)
  
          mailClient.Send(message)
  
      Catch ex As Exception
  
          PEH(&quot;SendEmail&quot;, &quot;frmA1Patrols&quot;, ex.Message)
  
      Finally
  
          mailClient.Dispose()
          message.Dispose()
  
      End Try
  
  
  End Sub
  </code></pre>