Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools


VB.net provides classes to send SMTP email. System.Web.Mail and System.Web.Mail.SmtpMail both class provides functionality to send emails but still to get full flexibility you should consider COM interop to use CDOSYS library. CDOSYS provides greater control on configuration (e.g. Specifying custom SMTP port other than 25).

Click here to copy the following block
Private Sub SendEmailTest()
 SendMail("toemail@binaryworld.net", _
  "fromemail@binaryworld.net", _
  "someCCemail@binaryworld.net", _
  "", _
  "Test HTML <B>Email</B>", _
  "Test email", _
  True, _
  "fromemail@binaryworld.net", _
  "DHANA", _
  25, _
  True, _
  "c:\clip.txt;c:\authors.txt")
End Sub

Private Sub SendMail(ByVal EmailTo As String, _
 ByVal EmailFrom As String, _
 Optional ByVal EmailCC As String = "", _
 Optional ByVal EmailBCC As String = "", _
 Optional ByVal EmailBody As String = "", _
 Optional ByVal EmailSubject As String = "", _
 Optional ByVal EmailWithReceipt As Boolean = False, _
 Optional ByVal EmailReceipTo As String = "", _
 Optional ByVal SMTPServer As String = "", _
 Optional ByVal SMTPPort As Integer = 25, _
 Optional ByVal IsBodyHTML As Boolean = True, _
 Optional ByVal AttachFileList As String = "")

 On Error GoTo errHandler

 Dim colAttachFiles() As String '//lile list
 Dim cdoConfig, cdoMessage As Object

 Const cdoSMTPServerPort = "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
 Const cdoDispositionNotificationTo = "urn:schemas:mailheader:disposition-notification-to"
 Const cdoReturnReceiptTo = "urn:schemas:mailheader:return-receipt-to"
 Const cdoSMTPServer = "http://schemas.microsoft.com/cdo/configuration/smtpserver"
 Const cdoSendUsingMethod = "http://schemas.microsoft.com/cdo/configuration/sendusing"


 'since this doesn't *have* to match the from address

 cdoConfig = CreateObject("CDO.Configuration")
 cdoMessage = CreateObject("CDO.Message")

 With cdoConfig.Fields
  .Item(cdoSendUsingMethod) = 2   'cdoSendUsingPort
  .Item(cdoSMTPServer) = SMTPServer
  .Item(cdoSMTPServerPort) = SMTPPort
  .Update()
 End With

 With cdoMessage
  '//This will be used to request sent receipt
  If EmailWithReceipt = True Then
   .Fields(cdoDispositionNotificationTo) = IIf(EmailReceipTo = "", EmailFrom, EmailReceipTo)
   .Fields(cdoReturnReceiptTo) = IIf(EmailReceipTo = "", EmailFrom, EmailReceipTo)
   .Fields.Update()
  End If
  .Configuration = cdoConfig

  .From = EmailFrom
  .To = EmailTo
  If EmailCC <> "" Then .CC = EmailCC
  If EmailBCC <> "" Then .BCC = EmailBCC
  .subject = EmailSubject

  If IsBodyHTML = True Then
   '//HTML Body
   '//.HTMLBody = "<U>This is a test for CDO.message</U>"
   .HTMLBody = EmailBody
  Else
   .TextBody = EmailBody
  End If

  Dim i As Integer
  '//process attachments
  If AttachFileList <> "" Then
   colAttachFiles = Split(Trim(AttachFileList), ";")

   For i = 0 To UBound(colAttachFiles)
    .AddAttachment(colAttachFiles(i))
   Next
  End If
  .Send()
 End With

 cdoMessage = Nothing
 cdoConfig = Nothing
 Exit Sub
errHandler:
 Err.Raise(Err.Number, Err.Description)
End Sub


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.