Comment on Tutorial - How to send email using VB.NET code By Issac



Comment Added by : Naresh

Comment Added at : 2011-05-24 07:27:12

Comment on Tutorial : How to send email using VB.NET code By Issac
Imports System.Web
Imports System.Net.Mail
Imports System.Text
Imports System.Web.Mail
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myMessage As New System.Web.Mail.MailMessage
TxtSendTo.Focus()
End Sub
Public Sub SendMailMultipleAttachments(ByVal From As String, _
ByVal sendTo As String, ByVal Subject As String, ByVal Body As String, Optional ByVal AttachmentFiles As ArrayList = Nothing, Optional ByVal CC As String = "", Optional ByVal BCC As String = "", Optional ByVal SMTPServer As String = "")
Dim i, iCnt As Integer
Dim myMessage As New System.Web.Mail.MailMessage
Try
With myMessage
.To = sendTo
.From = From
.Subject = Subject
.Body = Body
.BodyFormat = System.Web.Mail.MailFormat.Text
'CAN USER MAILFORMAT.HTML if you prefer

If CC <> "" Then .Cc = CC
If BCC <> "" Then .Bcc = BCC
If Not AttachmentFiles Is Nothing Then
iCnt = AttachmentFiles.Count - 1
For i = 0 To iCnt
If FileExists(AttachmentFiles(i)) Then _
.Attachments.Add(AttachmentFiles(i))
Next
End If
End With
If SMTPServer <> "" Then _
'System.Web.Mail.SmtpMail.SmtpServer = "mail.mavensystems.biz"
System.Web.Mail.SmtpMail.SmtpServer = "smtp.comcast.net"
End If
System.Web.Mail.SmtpMail.Send(myMessage)
Catch myexp As Exception
MsgBox(myexp.Message, MsgBoxStyle.Critical, Me.Text)
End Try
End Sub

Private Function FileExists(ByVal FileFullPath As String) _
As Boolean
If Trim(FileFullPath) = "" Then Return False
Dim f As New IO.FileInfo(FileFullPath)
Return f.Exists
End Function

'Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
' With odlgAttachment
' .InitialDirectory = "C:\"
' .Filter = "All Files (*.*)|*.*|HTML Files (*.htm;*.html)|*.htm|Microsoft Mail Documents (*.msg)|*.msg|Word Documents (*.doc)|*.doc|Excel Files(*.xl*)|*.xl*|Excel Worksheets (*.xls)|*.xls|Excel Charts (*.xlc)|*.xlc|PowerPoint Presentations (*.ppt)|*.ppt|Text Files (*.txt)|*.txt"
' .FilterIndex = 1

' The OpenFileDialog control only has an Open button, not an OK button.
' However, there is no DialogResult.Open enum so use DialogResult.OK.
' If .ShowDialog() = DialogResult.OK Then
' Dim fname As String
' fname = .FileName
' myMessage.Attachments.Add(New System.Web.Mail.MailAttachment(fname))
' Dim strFileName() As String = .FileName.Split(New Char() {CChar("\")})
' strFileName.Reverse(strFileName)
' lblfile.Text = lblfile.Text & strFileName(0) & ","
' End If
' End With
'End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call SendMailMultipleAttachments(TxtFrom.Text, TxtSendTo.Text, TxtSub.Text, TxtBody.Text, , TxtCc.Text, TxtBcc.Text)
MsgBox("Your Messege Be Sent", MsgBoxStyle.Information, "Messege Sent")
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'TxtFrom.Clear()
TxtSendTo.Clear()
TxtSub.Clear()
TxtBody.Clear()
TxtCc.Clear()
TxtBcc.Clear()
'lblfile.Clear()
TxtSendTo.Focus()
End Sub

'Private Sub Btn_Attach_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_Attach.Click
' Dim myMessage As New System.Web.Mail.MailMessage
' With odlgAttachment
' .InitialDirectory = "C:\"
' .Filter = "All Files (*.*)|*.*|HTML Files (*.htm;*.html)|*.htm|Microsoft Mail Documents (*.msg)|*.msg|Word Documents (*.doc)|*.doc|Excel Files(*.xl*)|*.xl*|Excel Worksheets (*.xls)|*.xls|Excel Charts (*.xlc)|*.xlc|PowerPoint Presentations (*.ppt)|*.ppt|Text Files (*.txt)|*.txt"
' .FilterIndex = 1

' ' The OpenFileDialog control only has an Open button, not an OK button.
' ' However, there is no DialogResult.Open enum so use DialogResult.OK.
' If .ShowDialog() = Windows.Forms.DialogResult.OK Then
' If IsNothing(TxtAttach) Then

' ' Clear the "(No Attachments)" default text in the ListView
' TxtAttach.Clear()
' End If
' 'TxtAttach.Add(New Attachment(.FileName))

' ' You only want to show the file name. The OpenFileDialog.FileName
' ' property contains the full path. So Split the path and reverse it
' ' to grab the first string in the array, which is just the FileName.
' Dim strFileName() As String = .FileName.Split(New Char() {CChar("\")})
' System.Array.Reverse(strFileName)
' 'TxtAttach.strFileName(0)
' End If
' End With

'End Sub
End Class


View Tutorial



Subscribe to Tutorials

Related Tutorials

Program using concept of byte long short and int in java

Update contents of a file within a jar file

Tomcat and httpd configured in port 8080 and 80

Java File

Java String

Count number of vowels, consonants and digits in a String in Java

Reverse a number in Java

Student marks calculation program in Java

Handling Fractions in Java

Calculate gross salary in Java

Calculate average sale of the week in Java

Vector in Java - Sample Program

MultiLevel Inheritance sample in Java

Multiple Inheritance sample in Java

Java program using Method Overriding

Archived Comments

1. thanks man really very nice and helpful...........
View Tutorial          By: Bakhtawar khan at 2012-12-05 05:54:18

2. Awesome script. works like a charm.


View Tutorial          By: blestab at 2011-03-02 04:32:35

3. Is site ki badolat main C++ mein paas ho gya !
View Tutorial          By: sharif at 2011-08-06 10:06:31

4. Hello sir pls send me
com.sun.speech.freett

View Tutorial          By: shanthi at 2013-03-22 11:18:56

5. the example program is very simple to understand a
View Tutorial          By: Zubilu at 2010-10-06 00:19:13

6. i have run the code successfully but it does not s
View Tutorial          By: amrish at 2010-12-11 07:00:28

7. ya it is better one and more helpful while learni
View Tutorial          By: sumithkrishnank at 2011-07-16 06:47:37

8. You just save ma arse, had a SQLite database, and
View Tutorial          By: codeRealm at 2011-11-13 12:58:05

9. this is a very good artical about floating &
View Tutorial          By: Gayathri at 2012-10-31 12:19:28

10. sooo nice...:****...love u...
View Tutorial          By: vinoo gopal rao at 2011-07-03 08:54:29