VB中发邮件中带附件怎么弄?急,谢谢!

june37 2005-01-10 09:34:04
Private Sub CmdSend_Click()
With MAPIMessages1
.MsgIndex = -1
.RecipDisplayName = txtSendTo.Text
.MsgSubject = txtSubject.Text
.MsgNoteText = txtMessage.Text
.SessionID = MAPISession1.SessionID.Send
End With
MsgBox "邮件发送完毕!", , "发送邮件"
End Sub

Private Sub Form_Load()
MAPISession1.SignOn
End Sub

Private Sub Form_Unload(Cancel As Integer)
MAPISession1.SignOff
End Sub
我现在这样不能发附件,大家帮下忙啊,谢谢!
...全文
274 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
daisy8675 2005-01-10
  • 打赏
  • 举报
回复
Private Sub cmdAttachment_Click()
On Error Resume Next

With CommonDialog1
.DialogTitle = "Insert Attachment"
.Filter = "All Files (*.*)|*.*"
.ShowOpen

If Dir(.FileName) <> "" Then
txtAttachment.Text = .FileName

' 显示 Attachment 的 Icon
oleAttachment.SourceDoc = .FileName
oleAttachment.CreateEmbed .FileName
Else
MsgBox "Attachment is not available.", vbCritical
End If
End With
End Sub

Private Sub cmdSend_Click()
' 开始 MAPI Session
MAPISession1.SignOn

' 当 MAPI Session 建立后,
' Session 所产生的 Handle 会存于 SessionID 属性中
If MAPISession1.SessionID <> 0 Then

' 建立 MAPIMessages 与 MAPISession 间之有效关联
MAPIMessages1.SessionID = MAPISession1.SessionID

' 建立新的 E-Mail Message
MAPIMessages1.Compose

' 收件者 (Recipient's Name)
MAPIMessages1.RecipDisplayName = txtName.Text

' 收件者的 E-Mail Address
MAPIMessages1.RecipAddress = "smtp: " & txtAddress.Text

' 是否要检查收件者有无存在于全域 (Global) 或个人 (Personal) 通讯簿里
MAPIMessages1.AddressResolveUI = True

' 检查收件者有无存在于全域 (Global) 或个人 (Personal) 通讯簿里
MAPIMessages1.ResolveName

' E-Mail 的主旨
MAPIMessages1.MsgSubject = txtSubject.Text

' E-Mail 的内文
MAPIMessages1.MsgNoteText = txtNote.Text

' 设定 Attachment (附件)
If Dir(txtAttachment.Text) <> "" Then
MAPIMessages1.MsgNoteText = MAPIMessages1.MsgNoteText & vbCrLf
MAPIMessages1.AttachmentPosition = Len(MAPIMessages1.MsgNoteText) - 1
MAPIMessages1.AttachmentPathName = txtAttachment.Text
End If

' 传送 E-Mail 且不显示"邮件对话盒" (直接传送)
MAPIMessages1.Send False
End If

' 结束 MAPI Session
MAPISession1.SignOff
End Sub

Private Sub cmdExit_Click()
End
End Sub

把上面的翻译下,帖成乱码了
gg137zeus 2005-01-10
  • 打赏
  • 举报
回复
gz
daisy8675 2005-01-10
  • 打赏
  • 举报
回复
Private Sub cmdAttachment_Click()
On Error Resume Next

With CommonDialog1
.DialogTitle = "Insert Attachment"
.Filter = "All Files (*.*)|*.*"
.ShowOpen

If Dir(.FileName) <> "" Then
txtAttachment.Text = .FileName

' 陪ボ Attachment  Icon
oleAttachment.SourceDoc = .FileName
oleAttachment.CreateEmbed .FileName
Else
MsgBox "Attachment is not available.", vbCritical
End If
End With
End Sub

Private Sub cmdSend_Click()
' 秨﹍ MAPI Session
MAPISession1.SignOn

' 讽 MAPI Session ミ,
' Session ┮玻ネ Handle 穦 SessionID 妮┦い
If MAPISession1.SessionID <> 0 Then

' ミ MAPIMessages 籔 MAPISession 丁ぇΤ闽羛
MAPIMessages1.SessionID = MAPISession1.SessionID

' ミ穝 E-Mail Message
MAPIMessages1.Compose

' Μン (Recipient's Name)
MAPIMessages1.RecipDisplayName = txtName.Text

' Μン E-Mail Address
MAPIMessages1.RecipAddress = "smtp: " & txtAddress.Text

' 琌璶浪琩ΜンΤ礚办 (Global) ┪ (Personal) 硄癟魁
MAPIMessages1.AddressResolveUI = True

' 浪琩ΜンΤ礚办 (Global) ┪ (Personal) 硄癟魁
MAPIMessages1.ResolveName

' E-Mail Ξ
MAPIMessages1.MsgSubject = txtSubject.Text

' E-Mail ずゅ
MAPIMessages1.MsgNoteText = txtNote.Text

' 砞﹚ Attachment (ン)
If Dir(txtAttachment.Text) <> "" Then
MAPIMessages1.MsgNoteText = MAPIMessages1.MsgNoteText & vbCrLf
MAPIMessages1.AttachmentPosition = Len(MAPIMessages1.MsgNoteText) - 1
MAPIMessages1.AttachmentPathName = txtAttachment.Text
End If

' 肚癳 E-Mail ぃ陪ボ"秎ン癸杠舶" (钡肚癳)
MAPIMessages1.Send False
End If

' 挡 MAPI Session
MAPISession1.SignOff
End Sub

Private Sub cmdExit_Click()
End
End Sub

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧