源代码如下:
Private Sub SendEmail(ByVal EmailAddress As String, ByVal Subject As String, ByVal NoteText As String, ByVal FilePath As String)
If EmailAddress = "" Then Exit Sub
On Error GoTo ErrMail
MAPISession1.LogonUI = False
MAPISession1.DownLoadMail = False
MAPISession1.SignOn
MAPIMessages1.SessionID = MAPISession1.SessionID
MAPIMessages1.Compose
MAPIMessages1.RecipAddress = EmailAddress
MAPIMessages1.MsgSubject = Subject
MAPIMessages1.MsgNoteText = NoteText
'Add the Attachment at the end of the message
MAPIMessages1.AttachmentPosition = Len(MAPIMessages1.MsgNoteText)
'Set the type to a data file
MAPIMessages1.AttachmentType = mapData
'Give it a name
'MAPIMessages1.AttachmentName = txtAttachmentName.Text
'Specify what file to send
MAPIMessages1.AttachmentPathName = FilePath
MAPIMessages1.Send False 'false means do not show the composition window
ErrMail:
If MAPISession1.SessionID <> 0 Then MAPISession1.SignOff
If Err.Number <> 0 Then Err.Raise Err.Number, Err.Source, Err.Description
End Sub
Private Sub SendEmail(ByVal EmailAddress As String, ByVal Subject As String, ByVal NoteText As String, ByVal FilePath As String)
If EmailAddress = "" Then Exit Sub
On Error GoTo ErrMail
MAPISession1.LogonUI = False
MAPISession1.DownLoadMail = False
MAPISession1.SignOn
MAPIMessages1.SessionID = MAPISession1.SessionID
MAPIMessages1.Compose
MAPIMessages1.RecipAddress = EmailAddress
MAPIMessages1.MsgSubject = Subject
MAPIMessages1.MsgNoteText = NoteText
'Add the Attachment at the end of the message
MAPIMessages1.AttachmentPosition = Len(MAPIMessages1.MsgNoteText)
'Set the type to a data file
MAPIMessages1.AttachmentType = mapData
'Give it a name
'MAPIMessages1.AttachmentName = txtAttachmentName.Text
'Specify what file to send
MAPIMessages1.AttachmentPathName = FilePath
MAPIMessages1.Send False 'false means do not show the composition window
ErrMail:
If MAPISession1.SessionID <> 0 Then MAPISession1.SignOff
If Err.Number <> 0 Then Err.Raise Err.Number, Err.Source, Err.Description
End Sub
解决方案 »
- Initialize和Load用的有什么区别
- 【视频】So True but Sad :面具人生--------今天你戴着什么样的面具呢?(摘于网络)
- VB datareport 总是打印前面已打印的数据记录
- 关于 FORM.SOHW
- 如何将WEbBrowser的状态反映到自荐的状态栏阿
- 在线等待——请问怎样用VB获得游戏摇杆、手柄的输入信息?
- 请教VB+Access(在线等待)
- 如何对注册表键值进行增加,打开,,修改,删除,的操作?
- 英格兰必败!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 《我想建立一个“最后更新日期”,有没有这方面的VB函数?省得我每次都手工输入》
- 再发一贴,给刚才给我解决on error问题的高手............分不多了,再给你们这些吧,以后还有很多问题,呵呵...
- 如何把时间字符串"Sun,5 Dec 2004 12:16:09 +0800"转换成常规格式"2004-12-05 12:16:09"
dim emailArr() as string
If EmailAddress = "" Then Exit Sub
emailArr = spilt(EmailAddress,"#")
for i = 0 to ubound(eamilArr) On Error GoTo ErrMail
MAPISession1.LogonUI = False
MAPISession1.DownLoadMail = False
MAPISession1.SignOn
MAPIMessages1.SessionID = MAPISession1.SessionID
MAPIMessages1.Compose
MAPIMessages1.RecipAddress = eamilArr(i)'*****************
MAPIMessages1.MsgSubject = Subject
MAPIMessages1.MsgNoteText = NoteText
'Add the Attachment at the end of the message
MAPIMessages1.AttachmentPosition = Len(MAPIMessages1.MsgNoteText)
'Set the type to a data file
MAPIMessages1.AttachmentType = mapData
'Give it a name
'MAPIMessages1.AttachmentName = txtAttachmentName.Text
'Specify what file to send
MAPIMessages1.AttachmentPathName = FilePath
MAPIMessages1.Send False 'false means do not show the composition window
ErrMail:
If MAPISession1.SessionID <> 0 Then MAPISession1.SignOff
If Err.Number <> 0 Then Err.Raise Err.Number, Err.Source, Err.Description
End Sub
调用的时候住地址和抄送地址用#号连接起来
好像还是不行阿!
比如我要发送给 [email protected],同时抄送这封信给 [email protected] !应该怎么改写
MAPISession1.LogonUI = False
MAPISession1.DownLoadMail = False
MAPISession1.SignOn
MAPIMessages1.SessionID = MAPISession1.SessionID
MAPIMessages1.Compose
MAPIMessages1.RecipIndex = 0
MAPIMessages1.RecipAddress = "[email protected]"
MAPIMessages1.RecipIndex = 1
MAPIMessages1.RecipAddress = "[email protected]"
MAPIMessages1.MsgIndex = -1
MAPIMessages1.RecipType = 2
MAPIMessages1.MsgSubject = Subject
MAPIMessages1.MsgNoteText = NoteText
MAPIMessages1.Send False 'false means do not show the composition window
If MAPISession1.SessionID <> 0 Then MAPISession1.SignOff