mauricerichard
asked on
Sending mail using credentials with impersonation
Hello Experts,
My old web server is dying (Windows Server 2000) and I'm transferring all of my .NET applications to the new web server. (Windows Server 2003) And everything it working great, except for webforms that send emails.
The webforms are setup to send emails using impersonation, and this still works fine on the old web server. But the new web server spits out the error: 5.7.1 Client was not authenticated. It's the same code that's working on the old server ... so I doubt it's the code.
I believe I've setup IIS on the new server the same as the old server. (Windows credentials, no anonymous access) So I'm not sure why this is causing a problem. I can fix it if I force credentials in my code, but this is not ideal.
Can anyone tell me why this might be failing?
Thanks!
Moe
My old web server is dying (Windows Server 2000) and I'm transferring all of my .NET applications to the new web server. (Windows Server 2003) And everything it working great, except for webforms that send emails.
The webforms are setup to send emails using impersonation, and this still works fine on the old web server. But the new web server spits out the error: 5.7.1 Client was not authenticated. It's the same code that's working on the old server ... so I doubt it's the code.
I believe I've setup IIS on the new server the same as the old server. (Windows credentials, no anonymous access) So I'm not sure why this is causing a problem. I can fix it if I force credentials in my code, but this is not ideal.
Can anyone tell me why this might be failing?
Thanks!
Moe
Try
Dim MailObj As New Net.Mail.SmtpClient
Dim message As New Net.Mail.MailMessage
With message
.IsBodyHtml = True
.Body = Get_Email_Body()
.BodyEncoding = System.Text.UTF8Encoding.UTF8
.Priority = Net.Mail.MailPriority.Normal
.Subject = "Our Email Subject"
.To.Add("somebody@somedomain.com")
.From = New Net.Mail.MailAddress(somebodyelse@somedomain.com")
End With
MailObj.Host = "ourhost.ourdomain.com"
MailObj.Port = "our port"
'Adding this line fixes it, but we'd prefer if impersonation worked instead
'MailObj.Credentials = New Net.NetworkCredential("SomeUser", "SomePassword", "OurDomain.com")
MailObj.Send(message)
Catch ex As Exception
'Something went wrong
lblError.Text = "Some Error"
End Try
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER