vb outlook中的问题

来源:百度知道 编辑:UC知道 时间:2024/06/17 14:38:11
Private Sub Command1_Click()
Dim out As Object 'createobject v ariable
'assign Outlook. Application to object variable
Set out = CreateObject("Outlook. Application")
With out.CreateItem(o1MailItem) 'using the Outlook object
'insert recipients one at a time with the Add method
'(thes e names are fictitious--replace with your own)
.Recipients.Add "maria@xxx.com " 'To:field
.Recipients.Add "casey@xxx.com " 'To:field
'to place users in the CC: field. Specify o1CC type
'Recipients.Add "mike_halvorson@classic.msn.com " ).Type = o1CC
.Subject = "Test Message" 'include a subject field
.Body = Text1.Text 'copy message text from text box
'insert attachments one at a time with the Add method
.Attachments.Add "c:\vb6sbs\less14\smile.bmp"
'finally, copy message to Outloo

Visual Basic 6中发送邮件的新方法
用VB6编写发送邮件的程序,有多种E-mail组件可供选择,如MAPIMessages、IIS4.0附带的CDONTS(NTS Collaboration Data Objects)以及许多第三方厂商开发的Email软件等。本文介绍用CDONTS开发VB下的邮件程序方法。
1. 确认已安装SMTP服务器
首先,必须确认在IIS服务器上已安装SMTP服务器,这是安装Option Pack时被缺省安装的选项。如果SMTP服务器已安装,在System32目录下会存在一个名为cdonts.dll的文件。

2. 最简单的邮件发送程序
以下是一个最简单的邮件发送程序,它由me@hotmail.net向abc@263.net发出一封标题为“Title”、内容为“Hello”的E-mail:
Private Sub cmdSendMail_Click()
Dim objMail as Object
Set objMail=CreateObject("CDFONTS.DLL")
ObjMail.Send "me@hotmail.net ", "690642614@qq.com","Title","Hello"
Set objMail=nothing
End Sub

3. 发送邮件附件
如果有附加的文件需要随同邮件传送,可以使用CDONTS的AttachFile方法:
Private Sub cmdSendMail_Click()
Dim objMail as Object
Set objMail=CreateObject("CDFONTS.DLL")
With ObjMail
.From= "me@hotmail.net "
.To= "abc@263.net"
.Subject="Title"