'Sending SMTP mail via port 25 using CDOSYS
'This VB sample uses CDOSYS to send SMTP mail using the cdoSendUsingPort option and specifying a SMTP host.
' Note: It is recommended that all input parameters be validated when they are
' first obtained from the user or user interface.
| Private Sub SendMessage(strTo As String, strFrom As String) |
| |
| 'Send using the Port on a SMTP server |
| Dim iMsg As New CDO.Message |
| Dim iConf As New CDO.Configuration |
| Dim Flds As ADODB.Fields |
| Dim strHTML |
| |
| Set Flds = iConf.Fields |
| |
| With Flds |
| .Item(cdoSendUsingMethod) = cdoSendUsingPort |
| .Item(cdoSMTPServer) = "mail.example.com" |
| 'Use SSL to connect to the SMTP server: |
| '.Item(cdoSMTPUseSSL) = True |
| .Item(cdoSMTPConnectionTimeout) = 10 |
| .Update |
| End With |
| |
| ' Build HTML for message body |
| strHTML = "<HTML>" |
| strHTMLstrHTML = strHTML & "<HEAD>" |
| strHTMLstrHTML = strHTML & "<BODY>" |
| strHTMLstrHTML = strHTML & "<b> This is the test HTML message body</b></br>" |
| strHTMLstrHTML = strHTML & "</BODY>" |
| strHTMLstrHTML = strHTML & "</HTML>" |
| |
| With iMsg |
| Set .Configuration = iConf |
| .To = strTo |
| .From = strFrom |
| .Subject = "This is a test CDOSYS message (Sent by Port)" |
| .HTMLBody = strHTML |
| '.TextBody = "This is the text body of the message..." |
| |
| .Send |
| End With |
| |
| ' cleanup of variables |
| Set iMsg = Nothing |
| Set iConf = Nothing |
| Set Flds = Nothing |
| |
| End Sub |
Article ID: 317, Created: 4/24/2009 at 9:59 AM, Modified: 4/25/2009 at 11:09 AM