ASP.NET 2.0 internal (intranet) web app using Integrated Auth + Impersonation. Developed on dev server (where classes reside) and published to production intranet server. Please bear with me, I'm not a .NET developer! Due to Exchange server move & upgrade an old app with mail features broke. I found the SMTP code in a class file on the dev server. The problem is that this code works fine if I call it locally as a function within a given page's code behind (mail functionality works) but if I try to call the same as a public class I get the following error:
The transport failed to connect to the server.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: The transport failed to connect to the server.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[COMException (0x80040213): The transport failed to connect to the server.
]
[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters) +0
System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams) +2501616
System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args) +72
[HttpException (0x80004005): The transport failed to connect to the server.
]
System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args) +119
System.Web.Mail.CdoSysHelper.Send(MailMessage message) +2684
System.Web.Mail.SmtpMail.Send(MailMessage message) +131
classes.Email.SendEmail(String strFrom, String strTo, String strSubject, String strBody) in \\Devserver\Inetpub\wwwroot\webprojects\classes\Email.vb:18
EducationSurvey.SendSurvey.SendEmailToAttendees(DataTable dtQualifiedParticipants, String strSubject, String strBody) +151
EducationSurvey.SendSurvey.Page_Load(Object sender, EventArgs e) +938
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
Because several parts of the app and possibly other old parts of our intranet are calling on this class (classes > Email), I'd like to fix it in place, or figure out how to move the class to the production server, where this app is published. Could authentication not be passing to the classes?
I'm hoping someone can give me clue, or tell me what to even ask! I'm out of my depth to be sure...Here's the function that works if included in the page code-behind:
Function SendNow(ByVal strFrom As String, ByVal strTo As String, ByVal strSubject As String, ByVal strBody As String) As Object
Dim msg As New MailMessage()
Dim smtp As SmtpClient
msg.From = New MailAddress(strFrom)
msg.To.Add(strTo)
msg.Subject = strSubject
msg.Body = strBody
smtp = New SmtpClient("echangeServerName")
smtp.UseDefaultCredentials = True
smtp.Send(msg)
Return True
End Function
However, if I put the same code back in the class file, Public class Email (which resides outside the project solution) I get the transport error above.