System.Web.Mail namespace?

K

kimiraikkonen

Hello, I'm trying to create a basic SMTP mail sender using that code,
i'm using VB.NET 2005 "express" but this namespace wasn't recognized...
(system.web.MAIL)

I'm only allowed to declare under that namespaces with "system.web":

System.Wb.AspNetHostingPermission
System.Web.AspNetHostingPermissionAttribute
System.Web.AspNetHostingPermissionLevel


Imports System.Web.mail
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click

Try
Dim insMail As New System.()
With insMail
.From = "(e-mail address removed)"
.To = "(e-mail address removed)"
.Subject = "test"
.Body = "test sending email"
End With
SmtpMail.SmtpServer = "your smtp server"
SmtpMail.Send(insMail)
Console.WriteLine("Successfully sent email message" +
vbCrLf)
Catch err As Exception
MsgBox("Couldn't send mail", MsgBoxStyle.Critical,
"Error")
End Try
End Sub


However, is there a limitation for "express" version or is there
something wrong about coding?

Thanks...
 
G

Guest

Imports System.Web.mail
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click

Try
Dim insMail As New System.()
With insMail
.From = "(e-mail address removed)"
.To = "(e-mail address removed)"
.Subject = "test"
.Body = "test sending email"
End With
SmtpMail.SmtpServer = "your smtp server"
SmtpMail.Send(insMail)
Console.WriteLine("Successfully sent email message" +
vbCrLf)
Catch err As Exception
MsgBox("Couldn't send mail", MsgBoxStyle.Critical,
"Error")
End Try
End Sub


However, is there a limitation for "express" version or is there
something wrong about coding?

What problem are you having?

Are you having trouble connecting to your SMTP server?
 
K

kimiraikkonen

What problem are you having?

Are you having trouble connecting to your SMTP server?

No, i get some error messages from Vb.net 2005 "express" starting with
"'Imports' statements must precede any declarations" continues with
other errors about declerations (e.g.insmail, smtpmail) as well.

Sorry for being beginner.

thanks...
 
G

Guest

No, i get some error messages from Vb.net 2005 "express" starting with
"'Imports' statements must precede any declarations" continues with
other errors about declerations (e.g.insmail, smtpmail) as well.

Sorry for being beginner.

thanks...

Imports should go at the very top of your class file.

Imports System.Web.Mail


Public Class....


Your Function Here

End Class
 
R

Rad [Visual C# MVP]

Hello, I'm trying to create a basic SMTP mail sender using that code,
i'm using VB.NET 2005 "express" but this namespace wasn't recognized...
(system.web.MAIL)

I'm only allowed to declare under that namespaces with "system.web":

System.Wb.AspNetHostingPermission
System.Web.AspNetHostingPermissionAttribute
System.Web.AspNetHostingPermissionLevel


Imports System.Web.mail
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click

Try
Dim insMail As New System.()
With insMail
.From = "(e-mail address removed)"
.To = "(e-mail address removed)"
.Subject = "test"
.Body = "test sending email"
End With
SmtpMail.SmtpServer = "your smtp server"
SmtpMail.Send(insMail)
Console.WriteLine("Successfully sent email message" +
vbCrLf)
Catch err As Exception
MsgBox("Couldn't send mail", MsgBoxStyle.Critical,
"Error")
End Try
End Sub


However, is there a limitation for "express" version or is there
something wrong about coding?

Thanks...

In the .NET framework 2 the MailMessage class is in the
System.Net.Mail namespace
 
K

kimiraikkonen

In the .NET framework 2 the MailMessage class is in the
System.Net.Mail namespace

--http://bytes.thinkersroom.com

Thanks, that's true! But still i get decleration errors about
"insmail", "smtpmail" syntaxes due to not being .net 2.0 classes. What
should be the exact ones?

Thanks!
 
K

kimiraikkonen

Ok, however i managed to configure some code OK.

Imports System.Net.Mail
Public Class Form1

Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSubmit.Click
Try
Dim message As New MailMessage(txtTo.Text, txtFrom.Text,
txtSubject.Text, txtBody.Text)
Dim emailClient As New SmtpClient(txtSMTPServer.Text)
emailClient.Send(message)
litStatus.Text = "Message Sent"

Catch ex As Exception
MsgBox("error")
End Try

End Sub

End Class



But i get "error" message because my smtp server needs authentication
(username, password).
How can i set these?

Thanks.
 
K

kimiraikkonen

However, added that authorization codes OK
but i get still "error" message for some reason.


Dim SMTPUserInfo As New System.Net.NetworkCredential(txtSMTPUser.Text,
txtSMTPPass.Text)
emailClient.UseDefaultCredentials = False
emailClient.Credentials = SMTPUserInfo

Is there a reliable and FREE Smtp server to test?
 
C

Cor Ligthert[MVP]

Kimi,

Click the menu Projects -> Add References -> Select in the .Net box the
"System.Net.Mail"

Set that import as is written in the other messages (to System.Net.Mail )
and it should have to work.

Cor
 
H

Herfried K. Wagner [MVP]

kimiraikkonen said:
Hello, I'm trying to create a basic SMTP mail sender using that code,
i'm using VB.NET 2005 "express" but this namespace wasn't recognized...
(system.web.MAIL)

Make sure your project contains a reference to "System.Web.dll".
 
R

Rad [Visual C# MVP]

However, added that authorization codes OK
but i get still "error" message for some reason.


Dim SMTPUserInfo As New System.Net.NetworkCredential(txtSMTPUser.Text,
txtSMTPPass.Text)
emailClient.UseDefaultCredentials = False
emailClient.Credentials = SMTPUserInfo

Is there a reliable and FREE Smtp server to test?

How does your SMTP server authenticate you? A quick way to test is
Telneting to the server and trying to login from the telnet session
using the username and password in your code
 
K

kimiraikkonen

How does your SMTP server authenticate you? A quick way to test is
Telneting to the server and trying to login from the telnet session
using the username and password in your code

--http://bytes.thinkersroom.com

Hello,
I've done by using Gmail free smtp server. Rad, i enabled SSL and
username/passwords as shown above and port 587(not needed
actually)There was no need to add special reference (dll).
"imports System.Net.Mail" done it.

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