Jump to content

Sending Mail Using Asp.net In Vb


Recommended Posts

Hi all

I am trying to send a mail through ASP.NET in VB and here is the exception I get when I run the application (the email part of the code below has been edited for anonymity). I am not using Code behind for the ASPX page. It works fine when I comment out the SmtpMail.Send code.

The requested body part was not found in this message. 
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 requested body part was not found in this message.

Source Error:


Line 58:    
Line 59:    SmtpMail.SmtpServer = "localhost"
Line 60:    SmtpMail.Send("someoneelse@something.com","someone@something.com","Subject","Body")
Line 61:    Response.Write("Mail sent")
Line 62:    


Source File: c:\inetpub\wwwroot\csci589\WebForm1.aspx    Line: 60

Stack Trace:


[COMException (0x800cce05): The requested body part was not found in this message.
]

[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 invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters) +473
  System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args) +29
  System.Web.Mail.LateBoundAccessHelper.SetProp(Type type, Object obj, String propName, Object propValue)
  System.Web.Mail.LateBoundAccessHelper.SetProp(Object obj, String propName, Object propValue)

[HttpException (0x80004005): Could not access 'CDO.Message' object.]
  System.Web.Mail.LateBoundAccessHelper.SetProp(Object obj, String propName, Object propValue)
  System.Web.Mail.CdoSysHelper.Send(MailMessage message)
  System.Web.Mail.CdoSysHelper.Send(String from, String to, String subject, String messageText)
  System.Web.Mail.SmtpMail.Send(String from, String to, String subject, String messageText)
  ASP.WebForm1_aspx.disp1(Object s, CommandEventArgs e) in c:\inetpub\wwwroot\csci589\WebForm1.aspx:60
  System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e)
  System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
  System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
  System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
  System.Web.UI.Page.ProcessRequestMain()

I am working on a project for my masters. Any help in this regard is greatly apreciated.

Bye

Link to comment
Share on other sites


Dont know if it helps U, here is my code in vbscript, maybe U could use the same object:

Option Explicit

Dim objEmail, objNetwork
Dim strComputerName

Set objEmail = CreateObject("CDO.Message")
Set objNetwork = CreateObject("Wscript.Network")

strComputerName = objNetwork.ComputerName

With objEmail
  .From =  strComputerName & "@domain.com"
  .To = "USD_Install@domain.com"
  .Subject = "Test message"
  .Textbody = "This is test message"
  .Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  .Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.domain.com"
  .Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
  .Configuration.Fields.Update
  .Send
End With

Set objEmail = Nothing
Set objNetwork = Nothing

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...