Using System.web.dll to send mail ?

G

Guest

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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Textbox1.Text="(e-mail address removed)"
TextBox2.Text="Husam"
TextBox3.Text="(e-mail address removed)"
TextBox4.Text="(e-mail address removed)"
TextBox5.Text="Test Mail"
TextBox6.Text="The New E-mail Sender is working well"
TextBox7.Text = "C:\husam.doc"
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(ByVal sender As System.Object, ByVal e As
System.EventArgs) 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, sUrlContentLocation As String
Dim iLoop1 As Integer

sTo = Trim(TextBox1.Text)
sFrom = Trim(TextBox2.Text)
sCc = Trim(TextBox3.Text)
sBcc = Trim(TextBox4.Text)
sSubject = Trim(TextBox5.Text)
sBody = Trim(TextBox6.Text)
sAttach = Trim(TextBox7.Text)
sBodyEncoding = Trim(TextBox8.Text)
sBodyFormat = Trim(TextBox9.Text)
sPriority = Trim(TextBox10.Text)
sUrlContentBase = Trim(TextBox11.Text)
sUrlContentLocation = 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.UrlContentBase = sUrlContentBase
MyMail.UrlContentLocation = sUrlContentLocation

Select Case TextBox8.Text
Case Encoding.UTF7.EncodingName : MyMail.BodyEncoding =
Encoding.UTF7
Case Encoding.UTF8.EncodingName : MyMail.BodyEncoding =
Encoding.UTF8
Case Else : MyMail.BodyEncoding = Encoding.ASCII
End Select

Select Case UCase(sBodyFormat)
Case "HTML" : MyMail.BodyFormat = MailFormat.Html
Case Else : MyMail.BodyFormat = MailFormat.Text
End Select

Select Case UCase(sPriority)
Case "HIGH" : MyMail.Priority = MailPriority.High
Case "LOW" : MyMail.Priority = MailPriority.Low
Case Else : MyMail.Priority = MailPriority.Normal
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(delim)
Dim myAttachment As MailAttachment = New
MailAttachment(sSubstr)
MyMail.Attachments.Add(myAttachment)
Next
End If

SmtpMail.SmtpServer = sMailServer
SmtpMail.Send(MyMail)

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.HttpException' 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
 
H

Herfried K. Wagner [MVP]

Husam said:
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.HttpException' occurred in
system.web.dll

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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top