Using System.web.dll to send mail ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Husam

    Using System.web.dll to send mail ?

    Hi EveryBody:

    I made windows application project as e-mail sender. This project consist of
    13 textbox and one label and one button. I add {system.web.dll } as refrance
    to this project to help me using some mail functions after I got hint from
    Mr. Paul Remblance to do so.

    The code is like the follwoing:

    Imports System.Web.Mail
    Imports System.Text

    Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
    System.EventArg s) Handles MyBase.Load
    Textbox1.Text=" husamal_ahmadi@ yahoo.com"
    TextBox2.Text=" Husam"
    TextBox3.Text=" husamalahmadi@g mail.com"
    TextBox4.Text=" dwebd@msn.com"
    TextBox5.Text=" Test Mail"
    TextBox6.Text=" The New E-mail Sender is working well"
    TextBox7.Text = "C:\husam.d oc"
    TextBox8.Text = Encoding.ASCII. EncodingName
    TextBox9.Text = "HTML"
    TextBox10.Text = "Normal"
    TextBox11.Text = "http://www.yahoo.com/"
    TextBox12.Text = "http://www.yahoo.com/"
    TextBox13.Text = "yahoo"

    End Sub

    Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
    System.EventArg s) Handles Button1.Click
    Dim sTo As String, sFrom As String, sSubject As String, sBody As
    String
    Dim sCc As String, sBcc As String
    Dim sAttach As String, sBodyEncoding As String
    Dim sBodyFormat As String, sMailServer As String, sPriority As String
    Dim sUrlContentBase As String, sUrlContentLoca tion As String
    Dim iLoop1 As Integer

    sTo = Trim(TextBox1.T ext)
    sFrom = Trim(TextBox2.T ext)
    sCc = Trim(TextBox3.T ext)
    sBcc = Trim(TextBox4.T ext)
    sSubject = Trim(TextBox5.T ext)
    sBody = Trim(TextBox6.T ext)
    sAttach = Trim(TextBox7.T ext)
    sBodyEncoding = Trim(TextBox8.T ext)
    sBodyFormat = Trim(TextBox9.T ext)
    sPriority = Trim(TextBox10. Text)
    sUrlContentBase = Trim(TextBox11. Text)
    sUrlContentLoca tion = Trim(TextBox12. Text)
    sMailServer = Trim(TextBox13. Text)

    Dim MyMail As MailMessage = New MailMessage

    MyMail.From = sFrom
    MyMail.To = sTo
    MyMail.Subject = sSubject
    MyMail.Body = sBody
    MyMail.Cc = sCc
    MyMail.Bcc = sBcc
    MyMail.UrlConte ntBase = sUrlContentBase
    MyMail.UrlConte ntLocation = sUrlContentLoca tion

    Select Case TextBox8.Text
    Case Encoding.UTF7.E ncodingName : MyMail.BodyEnco ding =
    Encoding.UTF7
    Case Encoding.UTF8.E ncodingName : MyMail.BodyEnco ding =
    Encoding.UTF8
    Case Else : MyMail.BodyEnco ding = Encoding.ASCII
    End Select

    Select Case UCase(sBodyForm at)
    Case "HTML" : MyMail.BodyForm at = MailFormat.Html
    Case Else : MyMail.BodyForm at = MailFormat.Text
    End Select

    Select Case UCase(sPriority )
    Case "HIGH" : MyMail.Priority = MailPriority.Hi gh
    Case "LOW" : MyMail.Priority = MailPriority.Lo w
    Case Else : MyMail.Priority = MailPriority.No rmal
    End Select

    ' Build an IList of mail attachments.
    If sAttach <> "" Then
    Dim delim As Char = ","
    Dim sSubstr As String
    For Each sSubstr In sAttach.Split(d elim)
    Dim myAttachment As MailAttachment = New
    MailAttachment( sSubstr)
    MyMail.Attachme nts.Add(myAttac hment)
    Next
    End If

    SmtpMail.SmtpSe rver = sMailServer
    SmtpMail.Send(M yMail)

    Label1.Text = "VB Message sent to " & MyMail.To

    End Sub

    When I debug this project And I connect to the net and I press the button
    which is send button I got an error message which said the follwoing:

    An unhandled exception of type 'System.Web.Htt pException' occurred in
    system.web.dll

    Additional information: Could not access 'CDO.Message' object.

    So any one can give me hint or redirection to solve this problem ?

    Any help will be appreciated

    regard's









  • Scott M.

    #2
    Re: Using System.web.dll to send mail ?

    Do you have a reference to the Collabrative Data Objects (CDO) library?

    "Husam" <Husam@discussi ons.microsoft.c om> wrote in message
    news:7330640F-30B3-4A56-B125-A18075121F48@mi crosoft.com...[color=blue]
    > Hi EveryBody:
    >
    > I made windows application project as e-mail sender. This project consist
    > of
    > 13 textbox and one label and one button. I add {system.web.dll } as
    > refrance
    > to this project to help me using some mail functions after I got hint from
    > Mr. Paul Remblance to do so.
    >
    > The code is like the follwoing:
    >
    > Imports System.Web.Mail
    > Imports System.Text
    >
    > Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
    > System.EventArg s) Handles MyBase.Load
    > Textbox1.Text=" husamal_ahmadi@ yahoo.com"
    > TextBox2.Text=" Husam"
    > TextBox3.Text=" husamalahmadi@g mail.com"
    > TextBox4.Text=" dwebd@msn.com"
    > TextBox5.Text=" Test Mail"
    > TextBox6.Text=" The New E-mail Sender is working well"
    > TextBox7.Text = "C:\husam.d oc"
    > TextBox8.Text = Encoding.ASCII. EncodingName
    > TextBox9.Text = "HTML"
    > TextBox10.Text = "Normal"
    > TextBox11.Text = "http://www.yahoo.com/"
    > TextBox12.Text = "http://www.yahoo.com/"
    > TextBox13.Text = "yahoo"
    >
    > End Sub
    >
    > Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
    > System.EventArg s) Handles Button1.Click
    > Dim sTo As String, sFrom As String, sSubject As String, sBody As
    > String
    > Dim sCc As String, sBcc As String
    > Dim sAttach As String, sBodyEncoding As String
    > Dim sBodyFormat As String, sMailServer As String, sPriority As
    > String
    > Dim sUrlContentBase As String, sUrlContentLoca tion As String
    > Dim iLoop1 As Integer
    >
    > sTo = Trim(TextBox1.T ext)
    > sFrom = Trim(TextBox2.T ext)
    > sCc = Trim(TextBox3.T ext)
    > sBcc = Trim(TextBox4.T ext)
    > sSubject = Trim(TextBox5.T ext)
    > sBody = Trim(TextBox6.T ext)
    > sAttach = Trim(TextBox7.T ext)
    > sBodyEncoding = Trim(TextBox8.T ext)
    > sBodyFormat = Trim(TextBox9.T ext)
    > sPriority = Trim(TextBox10. Text)
    > sUrlContentBase = Trim(TextBox11. Text)
    > sUrlContentLoca tion = Trim(TextBox12. Text)
    > sMailServer = Trim(TextBox13. Text)
    >
    > Dim MyMail As MailMessage = New MailMessage
    >
    > MyMail.From = sFrom
    > MyMail.To = sTo
    > MyMail.Subject = sSubject
    > MyMail.Body = sBody
    > MyMail.Cc = sCc
    > MyMail.Bcc = sBcc
    > MyMail.UrlConte ntBase = sUrlContentBase
    > MyMail.UrlConte ntLocation = sUrlContentLoca tion
    >
    > Select Case TextBox8.Text
    > Case Encoding.UTF7.E ncodingName : MyMail.BodyEnco ding =
    > Encoding.UTF7
    > Case Encoding.UTF8.E ncodingName : MyMail.BodyEnco ding =
    > Encoding.UTF8
    > Case Else : MyMail.BodyEnco ding = Encoding.ASCII
    > End Select
    >
    > Select Case UCase(sBodyForm at)
    > Case "HTML" : MyMail.BodyForm at = MailFormat.Html
    > Case Else : MyMail.BodyForm at = MailFormat.Text
    > End Select
    >
    > Select Case UCase(sPriority )
    > Case "HIGH" : MyMail.Priority = MailPriority.Hi gh
    > Case "LOW" : MyMail.Priority = MailPriority.Lo w
    > Case Else : MyMail.Priority = MailPriority.No rmal
    > End Select
    >
    > ' Build an IList of mail attachments.
    > If sAttach <> "" Then
    > Dim delim As Char = ","
    > Dim sSubstr As String
    > For Each sSubstr In sAttach.Split(d elim)
    > Dim myAttachment As MailAttachment = New
    > MailAttachment( sSubstr)
    > MyMail.Attachme nts.Add(myAttac hment)
    > Next
    > End If
    >
    > SmtpMail.SmtpSe rver = sMailServer
    > SmtpMail.Send(M yMail)
    >
    > Label1.Text = "VB Message sent to " & MyMail.To
    >
    > End Sub
    >
    > When I debug this project And I connect to the net and I press the button
    > which is send button I got an error message which said the follwoing:
    >
    > An unhandled exception of type 'System.Web.Htt pException' occurred in
    > system.web.dll
    >
    > Additional information: Could not access 'CDO.Message' object.
    >
    > So any one can give me hint or redirection to solve this problem ?
    >
    > Any help will be appreciated
    >
    > regard's
    >
    >
    >
    >
    >
    >
    >
    >
    >[/color]


    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: Using System.web.dll to send mail ?

      "Husam" <Husam@discussi ons.microsoft.c om> schrieb:[color=blue]
      > I made windows application project as e-mail sender. This project consist
      > of
      > 13 textbox and one label and one button. I add {system.web.dll } as
      > refrance
      > to this project
      > [...]
      > An unhandled exception of type 'System.Web.Htt pException' occurred in
      > system.web.dll
      >
      > Additional information: Could not access 'CDO.Message' object.[/color]

      Did you already take a look at <URL:http://www.systemwebma il.net/>?

      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://classicvb.org/petition/>

      Comment

      Working...