Hi,
I am trying to send an email through a web form to my email account but I am having problems
Is there any body out there to help
This is the code
Private Sub BSendR_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles BSendR.Click
Dim fromAs String = TextBoxE.Text
Dim mailtoAs String ="bookings@dotnet.itags.org.cubarent.co.uk"
Dim subjectAs String ="Booking Request"
Dim bodyAs String ="<html><body>UtilMailMessage001 - success</body></html>"
Try
SmtpMail.SmtpServer ="mail.cubarent.co.uk"
SmtpMail.Send(from, mailto, subject, body)
Catch exAs Exception
Label7.Text = ex.ToString' Show friendly error message.
Finally
Beep()' Beep after error processing.
End Try
End Sub
this is the error showing
System.Web.HttpException: Could not access 'CDO.Message' object. --> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. --> System.Runtime.InteropServices.COMException (0x80040213): The transport failed to connect to the server. -- End of inner exception stack trace -- at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters) at System.RuntimeType.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters) at System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args) -- End of inner exception stack trace -- at System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args) at System.Web.Mail.CdoSysHelper.Send(MailMessage message) at System.Web.Mail.CdoSysHelper.Send(String from, String to, String subject, String messageText) at System.Web.Mail.SmtpMail.Send(String from, String to, String subject, String messageText) at sancristobal.contactus.BSendR_Click(Object sender, EventArgs e)
This article explains in full detail some of the common reasons that error message occures:
http://www.systemwebmail.com/faq/4.2.3.aspx
Since you are getting the "TargetInvocationException" I would expect that the CDO Message Class in COM is not correctly registered.
First of all, make sure your Provider/Server accepts sending mail messages. Next, this line:
Dim fromAs String = TextBoxE.Text
The from address must be a valid mailaddress which is accepted by the Smtp server. Try your own address to check if that works. Also, skip the Html markup in your message:
Dim bodyAs String ="Message from " & TextBoxE.Text
I believe it will only show up as text anyway unless you use theMailMessage Classfor your mail message. I would actually recommend this as you will have many more options to manipulate your mail message.
0 comments:
Post a Comment