System.Net.Mail Question

  • Thread starter Thread starter Anthony P.
  • Start date Start date
A

Anthony P.

Hello Everyone,

I'm attempting to create a new MailMessage object by following a
tutorial and I can't seem to get it right according to VS 2008. I'm
hoping someone here can help me find out what I am doing wrong. I
would greatly appreciate it:

First, I am importing the System.Net.Mail class like this:

Imports System.Net.Mail

That works fine, no errors.

Now, in the subroutine where I need to create the new MailMessage
object, I am doing this:

Dim msg as Strong

MailMessage msg = new MailMessage()

At this point Visual Studio does two things:

1. It recreates the statement as MailMessage(msg = new MailMessage())

and

2. It throws two errors:

"MailMessage is a type that cannot be used as an expression"

and

"Name 'msg' is not declared'

It simply refuses to build. I am following the tutorial found here:
http://linkslash.com/05a47f

Can anyone help me figure this out?

Thanks!
Anthony
 
Oh, and before someone points it out, that 'Dim msg as Strong' really
is Dim Msg as String. I just mistyped it in the message.

Anthony
 
That's a tutorial in C# (hence all the semi-colons). In VB we say Dim .. As, as
in

Dim message As MailMessage = New MailMessage()

Just noticed that! Thank you. Works fine :-)

Anthony
 
Hello Everyone,

I'm attempting to create a new MailMessage object by following a
tutorial and I can't seem to get it right according to VS 2008. I'm
hoping someone here can help me find out what I am doing wrong. I
would greatly appreciate it:

First, I am importing the System.Net.Mail class like this:

Imports System.Net.Mail

That works fine, no errors.

Now, in the subroutine where I need to create the new MailMessage
object, I am doing this:

Dim msg as Strong

MailMessage msg = new MailMessage()

At this point Visual Studio does two things:

1. It recreates the statement as MailMessage(msg = new MailMessage())

and

2. It throws two errors:

"MailMessage is a type that cannot be used as an expression"

and

"Name 'msg' is not declared'

It simply refuses to build. I am following the tutorial found here:http://linkslash.com/05a47f

Can anyone help me figure this out?

Thanks!
Anthony

I'm relatively surprised no one's given you this link yet - it'll help
you with using System.Net.Mail with samples (in VB.NET and C#) and
plenty of how-to's

http://www.systemnetmail.com/

Thanks,

Seth Rowe [MVP]
 
try this ..


Imports System.Net.Mail
Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim mail As New System.Net.Mail.MailMessage()

Dim msgBody As String = String.Empty

Dim smtp As System.Net.Mail.SmtpClient = New SmtpClient()


mail.From = New System.Net.Mail.MailAddress("type your email here
like (e-mail address removed)", "type your name here and it will appear in the email")

mail.[To].Add("type the eamil you want to sent to like
(e-mail address removed)")

mail.Subject = "type the title here"

mail.Body = "type your message here"

mail.IsBodyHtml = True

smtp.Host = "smtp.gmail.com"

smtp.Port = 25

smtp.EnableSsl = True

smtp.Credentials = New System.Net.NetworkCredential("type your email
here like (e-mail address removed)", "Type password here")

Try



smtp.Send(mail)
MsgBox("the message sent successfully")
Catch ex As System.Exception


MsgBox(ex.Message)
End Try


End Sub

End Class
 
try this ..

Imports System.Net.Mail
Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim mail As New System.Net.Mail.MailMessage()

Dim msgBody As String = String.Empty

Dim smtp As System.Net.Mail.SmtpClient = New SmtpClient()

mail.From = New System.Net.Mail.MailAddress("type your email here
like (e-mail address removed)", "type your name here and it will appear in the email")

mail.[To].Add("type the eamil you want to sent to like
(e-mail address removed)")

mail.Subject = "type the title here"

mail.Body = "type your message here"

mail.IsBodyHtml = True

smtp.Host = "smtp.gmail.com"

smtp.Port = 25


A notification, I also used port 587 for Gmail to get it worked like
port 25.

Thanks,

Onur Güzel
 
Back
Top