Home All Groups Group Topic Archive Search About

VB .NET use MailMessage

Author
31 Aug 2006 5:31 AM
a
Hi
I want my application uses the instance of MailMessage and SmtpMail classes
to send email.
How can I add a reference to the System.Web.dll assembly to use these
classes?
Do the SmtpMail include the SMTP server, or it just uses the SMTP server of
the PC?
Thanks

Author
31 Aug 2006 6:38 AM
Cor Ligthert [MVP]
a,

Can you make yourself a little bit more anonym, there was somedays ago a
newbie, but I don't know if that is the same. If you are a newbie, we will
answer in another way than somebody who knows something more.

Thanks in advance,

Cor

Show quoteHide quote
"a" <a@mail.com> schreef in bericht
news:egE$26LzGHA.4308@TK2MSFTNGP03.phx.gbl...
> Hi
> I want my application uses the instance of MailMessage and SmtpMail
> classes
> to send email.
> How can I add a reference to the System.Web.dll assembly to use these
> classes?
> Do the SmtpMail include the SMTP server, or it just uses the SMTP server
> of
> the PC?
> Thanks
>
>
Author
1 Sep 2006 4:25 AM
a
Yes, I am a newbie.
Please explain it in detail.
Thanks a lot

Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> ¼¶¼g©ó¶l¥ó·s»D
:OJNmZfMzGHA.3***@TK2MSFTNGP03.phx.gbl...
>
>
> a,
>
> Can you make yourself a little bit more anonym, there was somedays ago a
> newbie, but I don't know if that is the same. If you are a newbie, we will
> answer in another way than somebody who knows something more.
>
> Thanks in advance,
>
> Cor
>
> "a" <a@mail.com> schreef in bericht
> news:egE$26LzGHA.4308@TK2MSFTNGP03.phx.gbl...
> > Hi
> > I want my application uses the instance of MailMessage and SmtpMail
> > classes
> > to send email.
> > How can I add a reference to the System.Web.dll assembly to use these
> > classes?
> > Do the SmtpMail include the SMTP server, or it just uses the SMTP server
> > of
> > the PC?
> > Thanks
> >
> >
>
>
Author
1 Sep 2006 12:13 PM
Timo
Add reference from menu:
    Project\Add Reference...
choose .NET tab and set reference to System.Net.Mail

Here's a simple mail sample:

Imports System.Net.Mail

  Public Sub SendSimpleMail(ByVal FromAddr As String, ByVal ToAddr As
String, _
    ByVal Subject As String, ByVal Body As String)
    '
    Dim Client As SmtpClient
    Dim Message As MailMessage

    ' Your SMTP server goes here
    Client = New SmtpClient("YOUR SMTP SERVER")
    ' You may also want to set Port and Timeout properties

    ' Simple plain text message
    Message = New MailMessage(FromAddr, ToAddr, Subject, Body)

    ' Send message
    Try
      Client.Send(Message)
    Catch ex As SmtpException
      MsgBox("Error: " & ex.Message & " Code: " & ex.StatusCode, _
        MsgBoxStyle.Exclamation Or MsgBoxStyle.OkOnly, "SMTP Error")
    End Try

    Message = Nothing
    Client = Nothing

  End Sub

Replace "YOUR SMTP SERVER" with a real Smtp server like "smtp.yourisp.com"
and call: SendSimpleMail("sen***@noaddress.com", "recipi***@noaddress.com",
"Hello", "This is a test")
(change email addresses of course).

SmtpClient does not include a SMTP server, you have to provide server
information yourself. You
can try to look in your email program's account settings what is your
outgoing server and use that.

A good place to start learning more about sending email is:
http://msdn2.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx
as you may want to use CC, BCC, attachments etc.

- Timo


Show quoteHide quote
"a" <a@mail.com> wrote in message
news:O8G016XzGHA.3656@TK2MSFTNGP04.phx.gbl...
> Yes, I am a newbie.
> Please explain it in detail.
> Thanks a lot
>
> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> ¼¶¼g©ó¶l¥ó·s»D
> :OJNmZfMzGHA.3***@TK2MSFTNGP03.phx.gbl...
>>
>>
>> a,
>>
>> Can you make yourself a little bit more anonym, there was somedays ago a
>> newbie, but I don't know if that is the same. If you are a newbie, we
>> will
>> answer in another way than somebody who knows something more.
>>
>> Thanks in advance,
>>
>> Cor
>>
>> "a" <a@mail.com> schreef in bericht
>> news:egE$26LzGHA.4308@TK2MSFTNGP03.phx.gbl...
>> > Hi
>> > I want my application uses the instance of MailMessage and SmtpMail
>> > classes
>> > to send email.
>> > How can I add a reference to the System.Web.dll assembly to use these
>> > classes?
>> > Do the SmtpMail include the SMTP server, or it just uses the SMTP
>> > server
>> > of
>> > the PC?
>> > Thanks
>> >
>> >
>>
>>
>
>
>
Author
1 Sep 2006 1:21 PM
Herfried K. Wagner [MVP]
"a" <a@mail.com> schrieb:
> I want my application uses the instance of MailMessage and SmtpMail
> classes
> to send email.
> How can I add a reference to the System.Web.dll assembly to use these
> classes?

There is a menu entry in the "Project" menu called "Add reference...".
Select "System.Web.dll" there, then import the namespace using 'Imports
System.Web'.  After doing so, you can use the types of the 'System.Web'
namespace directly in your code.

> Do the SmtpMail include the SMTP server, or it just uses the SMTP server
> of
> the PC?

It uses Windows' SMTP service or alternatively uses the SMTP server you
specify.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>