jacobymatt
asked on
Emailing through asp.net
I've written a program that sends a confirmation email after the user submits. The code points to the email server we have and the emails were sending fine when I was testing the program on my localhost. Now I have moved the application to the web server and it will not send an email. I've tried sending it to several addresses to make sure, but it fails to email every time. Here is my code:
Dim eMail As New MailMessage
eMail.Body = strMessage
eMail.From = "noreply@adtrav.com"
eMail.Subject = "Approval Needed"
eMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1")
eMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "matt@adtrav.com")
eMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "somepassword")
eMail.BodyFormat = MailFormat.Html
SmtpMail.SmtpServer = "mail.adtrav.com"
eMail.To = "matt.jacoby@adtrav.com"
SmtpMail.Send(eMail)
I am not familiar with the fields.add part, but I have been told that this can be given the email address and password of a valid account and it should work. I have also tried it without those three lines and it still doesn't work. Help! I am giving away all the points I have left and this is very urgent!
Dim eMail As New MailMessage
eMail.Body = strMessage
eMail.From = "noreply@adtrav.com"
eMail.Subject = "Approval Needed"
eMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1")
eMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "matt@adtrav.com")
eMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "somepassword")
eMail.BodyFormat = MailFormat.Html
SmtpMail.SmtpServer = "mail.adtrav.com"
eMail.To = "matt.jacoby@adtrav.com"
SmtpMail.Send(eMail)
I am not familiar with the fields.add part, but I have been told that this can be given the email address and password of a valid account and it should work. I have also tried it without those three lines and it still doesn't work. Help! I am giving away all the points I have left and this is very urgent!
Are you getting an error message? Are you sure the production server has access to the SMTP server?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the help guys. This is the error I was able to see when I ran the application from the web server. I just got in this morning so I will check those settings but I just wanted to go ahead and post this in case it was obvious what the problem was.
[COMException (0x80040213): The transport failed to connect to the server.
]
[TargetInvocationException : Exception has been thrown by the target of an invocation.]
System.RuntimeType.InvokeD ispMethod( String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters) +0
System.RuntimeType.InvokeM ember(Stri ng name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters) +473
System.Web.Mail.LateBoundA ccessHelpe r.CallMeth od(Object obj, String methodName, Object[] args) +58
[HttpException (0x80004005): Could not access 'CDO.Message' object.]
System.Web.Mail.LateBoundA ccessHelpe r.CallMeth od(Object obj, String methodName, Object[] args) +113
System.Web.Mail.CdoSysHelp er.Send(Ma ilMessage message) +1861
System.Web.Mail.SmtpMail.S end(MailMe ssage message) +150
ERC_RezApprove.form.sendEm ail(String strMessage, String strApprovee, String strTA, String strApprover) in c:\inetpub\wwwroot\ERC_Rez Approve\Au thForm.asp x.vb:695
ERC_RezApprove.form.btnReq uestApp_Cl ick(Object sender, EventArgs e) in c:\inetpub\wwwroot\ERC_Rez Approve\Au thForm.asp x.vb:739
System.Web.UI.WebControls. Button.OnC lick(Event Args e) +108
System.Web.UI.WebControls. Button.Sys tem.Web.UI .IPostBack EventHandl er.RaisePo stBackEven t(String eventArgument) +57
System.Web.UI.Page.RaisePo stBackEven t(IPostBac kEventHand ler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePo stBackEven t(NameValu eCollectio n postData) +33
System.Web.UI.Page.Process RequestMai n() +1292
[COMException (0x80040213): The transport failed to connect to the server.
]
[TargetInvocationException
System.RuntimeType.InvokeD
System.RuntimeType.InvokeM
System.Web.Mail.LateBoundA
[HttpException (0x80004005): Could not access 'CDO.Message' object.]
System.Web.Mail.LateBoundA
System.Web.Mail.CdoSysHelp
System.Web.Mail.SmtpMail.S
ERC_RezApprove.form.sendEm
ERC_RezApprove.form.btnReq
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.Page.RaisePo
System.Web.UI.Page.RaisePo
System.Web.UI.Page.Process
ASKER
Well, thanks anyway but I figured out that I needed to inlcude my mail server in my host file because it was trying to locate it by its external ip address instead of going through our network to reach it. But I don't really understand why it would not be able to find it by the external ip address. If anyone has a clue it would be nice to know why the external path would be a problem.