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. Mail me Codings in java of different programs
View Tutorial          By: vikram at 2008-09-12 06:04:42

2. Thanks lot.Its working good...... thanks lot lot..
View Tutorial          By: Mohanraj at 2011-12-07 05:23:26

3. excellent
View Tutorial          By: alok mishra at 2008-05-12 00:51:57

4. [English]
Good morning ... the question ari

View Tutorial          By: Federico at 2012-06-01 13:55:13

5. Nice article, Thank you
View Tutorial          By: kumar kasimala at 2010-04-26 21:09:25

6. Very good. Keep it up.
View Tutorial          By: jk at 2009-05-23 11:00:29

7. hi..it's very nice..can you send me the version fo
View Tutorial          By: daniel81 at 2010-02-11 09:19:36

8. hi,
i need to connect to server named xxx,i

View Tutorial          By: annamalai at 2012-05-21 10:09:52

9. Hi,

Is there a variable like GroupN

View Tutorial          By: SUNNYben at 2012-04-05 09:32:14

10. left shift output is wrong, for this results so ma
View Tutorial          By: naga sudha at 2011-04-20 04:26:40