正确的方法是使用 MAPI
这是 VB6 的一些代码:
Public Function MailtoWithAttachment(ByVal Recipient As String, ByVal Subject As String, ByVal Body As String, ByVal Attachment As String) As Boolean
Dim Message As MAPIMessage
Dim RecipientA() As Byte
Dim Recipients(0) As MapiRecip
Dim AttachmentA() As Byte
Dim Attachments(0) As MapiFile
Dim SubjectA() As Byte
Dim BodyA() As Byte
Dim Result As Long
'Set the recipient
RecipientA = StrConv(Recipient & vbNullChar, vbFromUnicode)
Recipients(0).lpName = VarPtr(RecipientA(0))
Recipients(0).RecipClass = MAPI_TO
Message.RecipCount = 1
Message.lpRecips = VarPtr(Recipients(0))
'Add the attachment
AttachmentA = StrConv(Attachment & vbNullChar, vbFromUnicode)
Attachments(0).lpPathName = VarPtr(AttachmentA(0))
Attachments(0).Position = -1
Message.FileCount = 1
Message.lpFiles = VarPtr(Attachments(0))
'Subject
SubjectA = StrConv(Subject & vbNullChar, vbFromUnicode)
Message.lpSubject = VarPtr(SubjectA(0))
'And body
BodyA = StrConv(Body & vbNullChar, vbFromUnicode)
Message.lpNoteText = VarPtr(BodyA(0))
'Try and send the email
Result = MAPISendMail(0, 0, ByVal VarPtr(Message), MAPI_DIALOG, 0&)
'Return false if there was a problem (ignoring canel)
MailtoWithAttachment = Result = 0 Or Result = 1
End Function
这使用来自MAPI32.bas的声明,并大量使用 unicode 到 ANSI 的转换和结构中的指针。
请注意,并非所有邮件客户端都支持这一点,唯一的解决方案是为每个客户端使用自定义界面。