Send e-mail by VB .NET Windows application

samiei
08-18-2004, 05:12 AM
Hi!
I am going to creat and send a mail message with a Win form Visual Basic .NET application. But the System.Web.Mail namespace may not be imported to the code (It just works in ASP .NET Web applications!?). What should I do? Which namespace is proper? Much obliged to you for your attention. Regards!

Yours thankfully,
M.Sadegh Samiei

PWNettle
08-18-2004, 02:41 PM
But the System.Web.Mail namespace may not be imported to the code (It just works in ASP .NET Web applications!?)

You can use the System.Web.Mail namespace in a winforms app...the trick is, as it is with ASP.Net use, that you need to have a valid Smtp server to point to so the mail can be sent.

This example runs fine for me from a VB.Net winforms app (but of course I used some valid addresses and a valid Smtp server *grin*):

' Requires that you add this imports statement to the top of your class:
' imports System.Web.Mail
Dim oMailMessage As New MailMessage

oMailMessage.To = "somebody@somedomain.com"
oMailMessage.From = "nuisance@spammers.com"
oMailMessage.Subject = "Test - " + DateTime.Now
oMailMessage.Body = "Testing, testing"

SmtpMail.SmtpServer = "xx.xx.xx.xx"
SmtpMail.Send(oMailMessage)

MessageBox.Show("Message Sent!")

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum