做到这一点,正确的方法是使用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转换和结构体中的指针。
请注意,并非所有的邮件客户端都支持此功能,对此,唯一的解决方案是使用每个客户端的自定义界面。
你需要证明你已经尝试过的东西,和社区会尽力帮助你。所以SO不会为你做你的工作。 http://stackoverflow.com/faq#questions – djv 2013-03-07 16:11:02
我试试这个,但它不支持附件System.Diagnostics.Process.Start(“mailto:”&“j”&“?Subject =”&“jola”&“ &Body =“&”txtBody“&”&Attach =“&”c:\ test.txt“) – user1725253 2013-03-07 16:42:40
此外,但我想允许用户使用它的电子邮件客户端:Dim SendFrom As MailAddress = New MailAddress(”test @ email.com “) 昏暗的SendTo作为MailAddress =新MailAddress(” [email protected]“) 昏暗MyMessage MAILMESSAGE作为=新MAILMESSAGE(SendFrom,的SendTo) MyMessage.Subject = ”HOLA“ MyMessage。 Body =“Body:” 'Dim attachFile As New Attachment(“C:\ test.txt”) 'MyMessage.Atta chments.Add(attachFile) 昏暗emailClient作为新SmtpClient( “yahoo.com”) emailClient.Timeout = Int32.MaxValue emailClient.Send(MyMessage) TextBox1.Text = “消息发送” – user1725253 2013-03-07 16:44:56