Results 1 to 2 of 2

Thread: Send mail using VB.net

  1. #1
    RogersNguyen is offline Senior Member
    Join Date
    Dec 2009
    Posts
    227
    Rep Power
    3

    Default Send mail using VB.net

    I am working on live project where I use VB.net as front and SQL as back end. There is one user information form in my project. I want to send this information through mail that’s why I want to right code for send mail .please give me some proper solution.

  2. #2
    MorganCooper is offline Senior Member
    Join Date
    Dec 2009
    Posts
    233
    Rep Power
    3

    Default

    Try this code which is helpful for you.

    Code:
    Invoke the Code widow and type the following statement above the Class declaration
    Imports System.Web.Mail
    Within the Class declaration, in the general section declare variables required for this project
    
    ' Variable which will send the mail
    Dim obj As System.Web.Mail.SmtpMail
    
    'Variable to store the attachments 
    Dim Attachment As System.Web.Mail.MailAttachment 
    
    'Variable to create the message to send
    Dim MailMsgg As New System.Web.Mail.MailMessage()    
    
    
    Double click on the addattachment button to add the code
    
    Type the following lines
    
    'Show open dialogue box to select the files to attach
    Dim Counter As Integer
    OFD.CheckFileExists = True
    OFD.Title = "Select file(s) to attach"
    OFD.ShowDialog()
    
    For Counter = 0 To UBound(OFD.FileNames)
    lstAttachment.Items.Add(OFD.FileNames(Counter))
    Next
    
    Double Click on the Removeattachment button 
    
    Type the following lines
    
    'Remove the attachments
    If lstAttachment.SelectedIndex > -1 Then
    lstAttachment.Items.RemoveAt(lstAttachment.SelectedIndex)
    End If
    
    
    
    Double Click on the Send button 
    
    Type the following lines
    
    
    Dim Counter As Integer
    
    'Validate the data
    If txtSMTPServer.Text = "" Then
    MsgBox("Enter the SMTP server info ...!!!", MsgBoxStyle.Information,  "Send Email")
    Exit Sub
    End If
    
    If txtFrom.Text = "" Then
                MsgBox("Enter the From email address ...!!!", MsgBoxStyle.Information, "Send Email")
    Exit Sub
    End If
    
    If txtTo.Text = "" Then
    MsgBox("Enter the Recipient email address ...!!!", MsgBoxStyle.Information, "Send Email")
    Exit Sub
    End If
    
    If txtSubject.Text = "" Then
    MsgBox("Enter the Email subject ...!!!", MsgBoxStyle.Information, "Send Email")
    Exit Sub
    End If
    
    'Set the properties
    ‘Assign the SMTP server
    obj.SmtpServer = txtSMTPServer.Text
    'Multiple recepients can be specified using ; as the delimeter
    ‘Address of the recipient
    MailMsgg.To = txtTo.Text
    
    
    ‘Your From Address
    ‘You can also use a custom header Reply-To for a different replyto address
    MailMsgg.From = "" & txtFromDisplayName.Text & " <" & txtFrom.Text & ">"
    
      
    'Specify the body format
    If chkFormat.Checked = True Then
    MailMsgg.BodyFormat = MailFormat.Html   'Send the mail in HTML Format
    Else
    MailMsgg.BodyFormat = MailFormat.Text
    End If
    
    'If you want you can add a reply to header 
    'MailMsgg.Headers.Add("Reply-To", "Manoj@geinetech.net")
    'custom headersare added like this
    'MailMsgg.Headers.Add("Manoj", "TestHeader")
    
    ‘Mail Subject
    MailMsgg.Subject = txtSubject.Text
    
    ‘Attach the files one by one
    For Counter = 0 To lstAttachment.Items.Count - 1
    Attachment = New MailAttachment(lstAttachment.Items(Counter))
    ‘Add it to the mail message
                MailMsgg.Attachments.Add(Attachment)
    Next
    
    ‘Mail Body
    MailMsgg.Body = txtMessage.Text
    ‘Call the send method to send the mail
    obj.Send(MailMsgg)

Similar Threads

  1. How to send e-mail through JSP
    By Erick Ballmer in forum Programming
    Replies: 3
    Last Post: 07-04-2010, 06:06 AM
  2. Send mail in ASP.net
    By MartinWilson in forum General Internet Terms
    Replies: 2
    Last Post: 06-22-2010, 01:45 PM
  3. Send mail from a Python script
    By ScottWright in forum Programming
    Replies: 0
    Last Post: 05-12-2010, 01:44 PM
  4. Send mail in PHP
    By Davisricky in forum Programming
    Replies: 2
    Last Post: 04-26-2010, 01:29 PM
  5. Send mail using Gmail SMTP
    By Davisricky in forum Software Jargons
    Replies: 2
    Last Post: 02-13-2010, 02:04 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48