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
Anthony P. - 11 May 2008 23:46 GMT
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
Steve Gerrard - 11 May 2008 23:57 GMT
> It simply refuses to build. I am following the tutorial found here:
> http://linkslash.com/05a47f
>
> Can anyone help me figure this out?
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()
Anthony P. - 12 May 2008 00:07 GMT
> > It simply refuses to build. I am following the tutorial found here:
> >http://linkslash.com/05a47f
[quoted text clipped - 5 lines]
>
> Dim message As MailMessage = New MailMessage()
Just noticed that! Thank you. Works fine :-)
Anthony
Muslem - 25 May 2008 11:40 GMT
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 me@gmail.com", "type your name here and it will appear in the email")
mail.[To].Add("type the eamil you want to sent to like
friend@hotmail.com")
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 me@gmail.com", "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
kimiraikkonen - 25 May 2008 12:41 GMT
> try this ..
>
[quoted text clipped - 29 lines]
>
> smtp.Port = 25
A notification, I also used port 587 for Gmail to get it worked like
port 25.
Thanks,
Onur Güzel
rowe_newsgroups - 12 May 2008 13:29 GMT
> Hello Everyone,
>
[quoted text clipped - 36 lines]
> 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]