Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Sending email with smtp server
Author:
Nilesh Vankani
E-mail:
Click to e-mail author
Submitted:
6/20/2005
Version:
VB.NET 2003
Compatibility:
VB.NET 2003, VB.NET 2005
Category:
Internet Programming
Views:
114540
This is a very simpale project to send email with the help of smpt server. Only small function you can use.......
Declarations:
Imports System.Web
Code:
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 myMessage As System.Web.Mail.MailMessage Dim i, iCnt As Integer Try ' myMessage = New System.Web.Mail.MailMessage 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 = "" 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.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 Cmdsend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cmdsend.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 CmdNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdNew.Click TxtFrom.Clear() TxtSendTo.Clear() TxtSub.Clear() TxtBody.Clear() TxtCC.Clear() TxtBcc.Clear() lblfile.Clear() TxtFrom.Focus() End Sub Private Sub CmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdClose.Click Me.Close() End Sub 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 FrmSendMail_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load myMessage = New System.Web.Mail.MailMessage End Sub
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2023 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement