Results 1 to 7 of 7

Thread: Email VB

  1. #1

    Default Email VB

    This tutorial will show you how to send email from your website using vb.net in plain text or HTML format. Below you will find all the functionality and code you need to do this in the simplest format.

    The following code is an example of the complete working project

    Code:
    <%@ Page Language="VB" %>
    <%@Import Namespace="System.Net.Mail" %>
    <script runat="server">
    Sub Page_Load(sender as Object, e as EventArgs)
    	
    	subHtmlEmail()
    	subPlainTextEmail()
    
    End sub
    
    Sub subPlainTextEmail()
    	
    	Dim strTo, strFrom, strBody, strSubject, strBcc As String
    	Dim bolHtml as boolean = false ' set the body content to plain text(false) or HTML(true)
    	strFrom = "info@yourwebsite.com"
    	strTo = "email1@theirdomain.com" ' ; Separates emails
    	strBcc = "email2@theirdomain.com; email3@theirdomain.com; email4@theirdomain.com" ' ; seperates emails
    	strSubject = "Subject for Plain Text email"
    	
    	strBody = "To whom it may concern," & vbCrLf & vbCrLf ' & vbCrLf is used for a line break
    	
    	strBody &= "This is an example of a plain text email" & vbCrLf & vbCrLf
    	
    	strBody &= "Best wishes," & vbCrLf
    	strBody &= "Yourwebsite.com"
    	
    	subEmail(strFrom, strTo, strBcc, strSubject, strBody, bolHtml)
    	
    End Sub
    
    Sub subHtmlEmail()
    	
    	Dim strTo, strFrom, strBody, strSubject, strBcc As String
    	Dim bolHtml as boolean = true ' set the body content to plain text(false) or HTML(true)
    	strFrom = "info@yourwebsite.com"
    	strTo = "email1@theirdomain.com" ' ; Separates emails
    	strBcc = "email2@theirdomain.com; email3@theirdomain.com; email4@theirdomain.com" ' ; Separates emails
    	strSubject = "Subject for HTML email"
    
    	strBody = "<html><head></head><body>"
    
    	strBody &= "To whom it may concern,<br><br>"
    	
    	strBody &= "This is an example of an HTML format email<br><br>" 
    	
    	strBody &= "<img src=""http://www.coolwebawards.com/image/forum_logo.gif"" /><br><br>" 
    
    	strBody &= "Best wishes,<br>" 
    	strBody &= "Yourwebsite.com"
    	
    	strBody &= "</body></html>"
    
    	subEmail(strFrom, strTo, strBcc, strSubject, strBody, bolHtml)
    
    End Sub
    
    
    Sub subEmail(strFrom, strTo, strBcc, strSubject, strBody, bolHtml)
    	
    	'*** Written by user CWA, CoolWebAwards.com Forums. 24 February 2010
    	'*** http://forum.coolwebawards.com/threads/102-Email-VB
    	
    	Dim strMailServer As String = "mail.yourwebsite.com"
    	
    	Dim objMail As New MailMessage()
    	objMail.From = New MailAddress(strFrom)
    	dim i as integer
    	dim arrArray AS Array
    	
    	arrArray=Split(strTo, ";")
    	For i = 0 to arrArray.Length - 1
    		objMail.To.Add(arrArray(i))
    	Next
    
    	arrArray=Split(strBcc, ";")
    	For i = 0 to arrArray.Length - 1
    		If not arrArray(i) = "" Then objMail.Bcc.Add(arrArray(i))
    	Next
    		
    	objMail.Subject = strSubject
    	objMail.Body = strBody
    	objMail.IsBodyHtml = bolHtml
    	Dim smtp As New SmtpClient(strMailServer)
    	'smtp.Credentials = New System.Net.NetworkCredential("username", "password")
    	smtp.Send(objMail)
    	
    End Sub
    </script>
    Setup

    1. Variables to be passed to “subEmail”
    strFrom – The email address the email is sent from
    strTo – The email address that the email will be sent to. Use “;” to separate emails is you like to add more than one
    strBcc – Send a Blind Carbon Copy (Bcc) to these email address/es. Use “;” to separate emails is you like to add more than one
    strSubject – Email subject line
    strBody – The body text for your email
    bolHtml – Whether or not the email body is HTML (true) or plain text (false)

    2. Change the following line to your mail server address

    Code:
    Dim strMailServer As String = "mail.yourwebsite.com"
    3. If your mail server requires authentication, you can uncomment the following line to pass the username and password values which must also be setup on your mail server

    Code:
    smtp.Credentials = New System.Net.NetworkCredential("username", "password")
    CWA - CoolWebAwards.com

  2. #2

    Default

    Good piece of information. It solved one of my problems.

  3. #3

    Default

    With the MAPI component, you can actualize and forward a message, cover a file attachment, verify the recipient's email abode adjoin the email system's abode book and lots more.

  4. #4
    Ruby Star member
    Join Date
    Jun 2011
    Posts
    458

    Default

    Im new newbie learning through the html file and vb. New to html, learn the basic vb. Read the code to send email

    In VB I would love to, because I heard the best way to learn code is to learn code is available and find out the meaning of the code if they learn to understand the code very quickly. Thanks for share.
    BDS Real Estate Company
    Go to my website rao vat ban nha to learn about real estate in Vietnam: Home sales , Apartment for sale, Feng Shui ...

  5. #5

    Default

    I have a knowledge about HTML and C language. The codes are easy and feels that it can be used without much effort. I believe that code could have been little shorter. Some of the object oriented features might have been used. Well never the less, the can be used. If server side script were there along with the script given, they would have been much more easier to understand. I still have a doubt how and where to write the codes. Please write about IDE used for .net environment.

  6. #6
    Sapphire Star member
    Join Date
    Aug 2011
    Posts
    70

    Default

    VB.NET using SMTP protocol for sending email , SMTP stands for Simple Mail Transfer Protocol.

  7. #7

    Default

    With the MAPI component, you can update and send a message, which covers an attachment, check e-mail address book still remained by the email system and more.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •