Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Sending Email Using Visual Basic.Net

Author: DevASP
Download Source Code : 546_Email.zip

In this Article I Will Explain you the easiest Way To send mail using the client's mail system, create a hyperlink using the mailto protocol.

For example, the following HTML shows a hyperlink that creates a new message with a subject line and a short message body:

<A href="mailto:someone@microsoft.com?SUBJECT=Sending from a client & BODY=Some message text.">

When the use clicks the preceding hyperlink, the client' s browser starts the client' s mail application and creates a message.

You can use the mailto protocol in place of any destination URL in a server control or an HTML control. For instance, the following HTML defines a Hyperlink server control that sends a mail message

<asp:HyperLink ID="hypMail" NavigateUrl="mailto:salman@gmail.com?
SUBJECT=Mailing a Webform&BODY=Some message text."
Runat="server">Send mail.</asp:HyperLink>

Sending Mail from the Server

When you send mail from the server, ASP.NET does not start the client' s mail system to allow the user to compose the message to send, to add attachments, or to validate addresses. Instead, you compose the message in code and send it one of two ways:

·         You can send a simple message using the SmtpMail class' s Send method.

·         You can create a more complex message using the MailMessage class, and then send that message using the SmtpMail class' s Send method.

Both the SmtpMail class and the MailMessage class are part of the System.Web.Mail namespace in the .NET Framework, so add the following statement at the beginning of your module to simplify references to those classes in code.

Imports System.Web.Mail

Private Sub butMail_Click(ByVal sender As System.Object, +
      ByVal e As System.EventArgs) Handles butMail.Click
    ' Create the message.
    Dim mailNew As New MailMessage()
    ' Set the message properties.
    mailNew.From = "someone@microsoft.com"
    mailNew.To = "jesse@contoso.com"
    mailNew.Subject = "This is the subject text."
    mailNew.Body = "This is the message text."
    ' Create an attachment.
    Dim atcItem As New _
    MailAttachment(Server.MapPath(Request.ApplicationPath) & "\joey.jpg")
    ' Attach it to the message.
    mailNew.Attachments.Add(atcItem)
    ' Send the message.
    SmtpMail.Send(mailNew)
End Sub

 

Source code is given with this article .And theses Functions Are Given in attached application. It is recommended run application first. 

Article Comments
i want to know to send colour text in vb.net using colordialog and send font styles using fontdialog in windows application

Posted on 3/15/2007 12:59:26 AM by thanigaivasan

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How- Client Server Using VB.Net (Part 3)

Disclaimer - Privacy
© 2002-2017 DevASP.net