首先,在工程里引用一個(gè)COM:Microsoft CDO for Windows 2000 Library
接著他應(yīng)該會(huì)自動(dòng)imports倆組件,如果沒(méi)有的話你自己寫(xiě):
- Imports CDO
- Imports ADODB
Imports CDO
Imports ADODB
代碼:
- Private Sub SendTestCDOMessage()
- Dim cdoObj As Object
- cdoObj = CreateObject("cdo.Message")
-
-
-
-
-
-
-
- cdoObj.Configuration.Fields.item _
- ("http://schemas.microsoft.com/cdo/configuration/sendusing") _
- = CDO.CdoSendUsing.cdoSendUsingPort
-
-
- cdoObj.Configuration.Fields.item _
- ("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
- = "smtp.163.com"
-
-
- cdoObj.Configuration.Fields.item _
- ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") _
- = 465
-
-
- cdoObj.Configuration.Fields.item _
- ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") _
- = CDO.CdoProtocolsAuthentication.cdoBasic
-
-
-
- cdoObj.Configuration.Fields.item _
- ("http://schemas.microsoft.com/cdo/configuration/sendusername") _
- = "bbb@163.com"
- cdoObj.Configuration.Fields.item _
- ("http://schemas.microsoft.com/cdo/configuration/sendpassword") _
- = "password"
- cdoObj.Configuration.Fields.item _
- ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") _
- = "true"
-
-
-
- cdoObj.Configuration.Fields.Update()
-
-
-
- cdoObj.AddAttachment("C:\\1010.txt", "", "")
-
-
-
- cdoObj.To = "aaa@qq.com"
- cdoObj.From = "bbb@163.com"
- cdoObj.Subject = "cdo Test"
- cdoObj.TextBody = "Send Email from vb.net using cdo"
-
-
-
- cdoObj.Send()
-
-
- cdoObj = Nothing
- MsgBox("Done.")
- End Sub