VB.NET 2005 System.Net.Mail Problem

G

Guest

I am trying to send a simple mail message using windows forms in VB.NET 2005.
When executing the code, I get a general 'Configuration system failed to
initialize' error message when the code instatiates a new MailMessage object
(see below) My form has the following code:

Imports System.Net.Mail

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
SendMail("(e-mail address removed)")
End Sub

Private Sub SendMail(ByVal pTo As String)
Dim sSubject As String = "Test"
Dim sBody As String = "Test message."

' *** Error happens here ***
Dim oMail As New MailMessage

oMail.To.Add(New MailAddress(pTo))
oMail.Subject = sSubject
oMail.Body = sBody

Dim oSmtp As New SmtpClient
oSmtp.Send(oMail)

End Sub
End Class

My app.config file has the following:

<system.net>
<mailSettings>
<smtp from="(e-mail address removed)">
<network host="(localhost)" port="25" />
</smtp>
</mailSettings>
</system.net>

The Default SMTP Virtual Servier is running in IIS.

Could someone please provide some help with this?? Thanks.

Tim
 
I

irokosoft

Hi. I am having exact same problem, but with a console app.
Did you ever get this resolved?
 
G

Guest

Tim, I am having an EMail problem also from my VB 2005 Express form.

I saw your message. I do not understand this in your message. I have never
seen it listed this way before and I have written several windows appl
programs.

What is strange to me is: this below lines about your App.config file.
My app.config file has the following:

<system.net>
<mailSettings>
<smtp from="(e-mail address removed)">
<network host="(localhost)" port="25" />
</smtp>
</mailSettings>
</system.net>

I have made form for E-Mail. I have entered code but the Import system does
not work. It has squiggly line underneath it showing it is not communicating.
Will not build.

Public Class Form3Bio1
System.Net.Mail.SmtpClient
Imports System.Net.Mail
' I XXX out certain entrys below just for this publication.

Dim emailSender As SmtpClient
Dim theMessage As MailMessage
Dim SHost As String = ("smtp.XXXXX.com")
Dim Passwd As String = ("Harold45")
Dim Recv As String = ("(e-mail address removed)")
Dim Sndr As String = ("(e-mail address removed)")
Dim Body As String = (Form4Bio1.TextBox5.Text) +
(Form4Bio1.ListBox1.Items)
emailSender = New System.Net.Mail.SmtpClient( _
SHost)

theMessage = New MailMessage
theMessage.From = New MailAddress(Sndr)
theMessage.To.Add(Recv)
theMessage.Subject = (Form4Bio1.TextBox4.Text)
theMessage.password = (Passwd)
theMessage.Body = (Form4Bio1.TextBox5.Text) +
(Form4Bio1.ListBox1.Items)

I have tried Importing the System.Net.Mail but can't find it. I have .Net
2.0 installed.
My form system just does not allow System nor recognize the System.Net
Thanks for your kind help in advance.
Tim, is my problem because I have not set up a Config file like you listed
above?
I do not know where a Config file is made. Thanks.
 

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