| | |
Option of sending email either by Outlook or CDO
Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Jan 2008
Posts: 33
Reputation:
Solved Threads: 0
I have two checkboxes on my Form1, one is called "CheckOE" and the other "CheckCDO"
I would like to have an option of sending email message using either Outlook or CDO.
Both email codes work fine if placed in the button alone, but I dont' know how to skip either Outlook or CDO code depending on what checkbox is checked and both codes placed inside the same button. I have typed If Else there just to give a clue on what I want to be able to accomplish. Please help! I doing this in MS VB 2008 Express. Here is my code:
'*******************************
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If CheckOE = 1 Then
'Create a new message using Outlook
objOutlk = CreateObject("Outlook.Application")
objMail = objOutlk.createitem(olMailItem)
If ComboBox1.Text = "" Then
objMail.To = ""
Else
End If
If ComboBox1.Text = "" Then
objMail.To = ""
Else
End If
objMail.cc = ""
'Set up Subject Line)
objMail.subject = ""
'Add the body
If ComboBox1.Text = "" Then
strMsg = "," & "" & vbCrLf
strMsg = strMsg & "" & vbCrLf
strMsg = strMsg & "" & vbCrLf
strMsg = strMsg & "" & vbCrLf
strMsg = strMsg & "" & vbCrLf
strMsg = strMsg & "" & vbCrLf
strMsg = strMsg & "" & vbCrLf
objMail.attachments.add("")
objMail.body = strMsg
Else
End If
objMail.Display()
objMail = Nothing
objOutlk = Nothing
Else
End If
'*******************************
If CheckCDO = 1 Then
'Create and send message ussing CDO
Const ForReading = 1
Dim strBody
Dim fso = CreateObject("Scripting.FileSystemObject")
Dim f = fso.OpenTextFile("", ForReading)
strBody = f.ReadAll
' Close the file
f.Close()
f = Nothing
fso = Nothing
Dim iMsg, iConf, Flds
Dim schema As String
Dim SendEmail As Integer
iMsg = CreateObject("CDO.Message")
iConf = CreateObject("CDO.Configuration")
Flds = iConf.Fields
schema = "http://schemas.microsoft.com/cdo/configuration/"
Flds.Item(schema & "sendusing") = 2
Flds.Item(schema & "smtpserver") = ""
Flds.Item(schema & "smtpserverport") = 25
Flds.Item(schema & "smtpauthenticate") = 1
Flds.Item(schema & "sendusername") = ""
Flds.Item(schema & "sendpassword") = ""
Flds.Item(schema & "smtpusessl") = 0
Flds.Update()
With iMsg
.To = ""
.CC = ""
.From = ""
.Subject = ""
.HTMLBody = strBody '""
.AddAttachment("")
.Sender = ""
.Organization = ""
.ReplyTo = ""
.Configuration = iConf
SendEmail = .Send
End With
iMsg = Nothing
iConf = Nothing
Flds = Nothing
Else
End If
End Sub
End Class
'*******************************
I would like to have an option of sending email message using either Outlook or CDO.
Both email codes work fine if placed in the button alone, but I dont' know how to skip either Outlook or CDO code depending on what checkbox is checked and both codes placed inside the same button. I have typed If Else there just to give a clue on what I want to be able to accomplish. Please help! I doing this in MS VB 2008 Express. Here is my code:
'*******************************
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If CheckOE = 1 Then
'Create a new message using Outlook
objOutlk = CreateObject("Outlook.Application")
objMail = objOutlk.createitem(olMailItem)
If ComboBox1.Text = "" Then
objMail.To = ""
Else
End If
If ComboBox1.Text = "" Then
objMail.To = ""
Else
End If
objMail.cc = ""
'Set up Subject Line)
objMail.subject = ""
'Add the body
If ComboBox1.Text = "" Then
strMsg = "," & "" & vbCrLf
strMsg = strMsg & "" & vbCrLf
strMsg = strMsg & "" & vbCrLf
strMsg = strMsg & "" & vbCrLf
strMsg = strMsg & "" & vbCrLf
strMsg = strMsg & "" & vbCrLf
strMsg = strMsg & "" & vbCrLf
objMail.attachments.add("")
objMail.body = strMsg
Else
End If
objMail.Display()
objMail = Nothing
objOutlk = Nothing
Else
End If
'*******************************
If CheckCDO = 1 Then
'Create and send message ussing CDO
Const ForReading = 1
Dim strBody
Dim fso = CreateObject("Scripting.FileSystemObject")
Dim f = fso.OpenTextFile("", ForReading)
strBody = f.ReadAll
' Close the file
f.Close()
f = Nothing
fso = Nothing
Dim iMsg, iConf, Flds
Dim schema As String
Dim SendEmail As Integer
iMsg = CreateObject("CDO.Message")
iConf = CreateObject("CDO.Configuration")
Flds = iConf.Fields
schema = "http://schemas.microsoft.com/cdo/configuration/"
Flds.Item(schema & "sendusing") = 2
Flds.Item(schema & "smtpserver") = ""
Flds.Item(schema & "smtpserverport") = 25
Flds.Item(schema & "smtpauthenticate") = 1
Flds.Item(schema & "sendusername") = ""
Flds.Item(schema & "sendpassword") = ""
Flds.Item(schema & "smtpusessl") = 0
Flds.Update()
With iMsg
.To = ""
.CC = ""
.From = ""
.Subject = ""
.HTMLBody = strBody '""
.AddAttachment("")
.Sender = ""
.Organization = ""
.ReplyTo = ""
.Configuration = iConf
SendEmail = .Send
End With
iMsg = Nothing
iConf = Nothing
Flds = Nothing
Else
End If
End Sub
End Class
'*******************************
![]() |
Other Threads in the VB.NET Forum
- Previous Thread: VB.NET Toolbox Tricks !
- Next Thread: VB.NET Soap Method Not Exposed
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2005 2008 access add arithmetic array assignment basic binary bing box button buttons center check code combobox component connectionstring convert cpu crystalreport data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dosconsolevb.net dropdownlist editvb.net excel file-dialog firewall folder ftp google hardcopy image images isnumericfuntioncall login math memory mobile ms mssqlbackend mysql navigate net networking opacity output peertopeervideostreaming picturebox1 port print printpreview problemwithinstallation project record reports" reuse save savedialog searchbox serial soap storedprocedure string tcp temp text textbox timer toolbox trim updown useraccounts usercontrol vb vb.net vb.netcode vb.nettoolboxvisualbasic2008sidebar vb2008 vbnet view visual visualbasic visualbasic.net visualstudio web wpf





