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. hello

my problem is how to intrega

View Tutorial          By: mihir patel at 2013-11-28 18:10:04

2. very helpful & gud tutorial...
thanks..

View Tutorial          By: Narpinder Sharma at 2011-06-27 03:12:20

3. ok good.But what about plug-in's Information.
View Tutorial          By: Ramarao at 2010-01-31 07:32:02

4. thats is really too gud... very easy example to un
View Tutorial          By: radhika at 2011-11-27 16:32:25

5. why we use the java in networking and What are the
View Tutorial          By: ali mohammed at 2015-10-11 23:03:40

6. good site for buggners
View Tutorial          By: sivannaadhbaazi karampudi at 2011-12-01 15:37:55

7. I am getting this error with Minecraft; Feed the B
View Tutorial          By: LadyKianna at 2013-03-11 05:52:54

8. There was no sharing of volatile variable in the p
View Tutorial          By: Rajesh Poppoppu at 2011-12-30 13:04:42

9. Thank you very much for such a nice topic
View Tutorial          By: CHANDAN at 2012-11-01 04:40:02

10. Hi ,

Is there any way to export con

View Tutorial          By: Nithya Duraiswamy at 2009-03-03 21:32:05