-2

I,m looking a way to open the default email client that has the computer installed (Outlook or groupwise) and attach a file. The user will be entering the other information in the email client.

Tried:

Dim SendFrom As MailAddress = New MailAddress("test@email.com")
Dim SendTo As MailAddress = New MailAddress("test@email.com") 
Dim MyMessage As MailMessage = New MailMessage(SendFrom, SendTo) 
MyMessage.Subject = "Hola" 
MyMessage.Body = "Body:" 
'Dim attachFile As New Attachment("C:\test.txt") 
'MyMessage.Attachments.Add(attachFile) 
Dim emailClient As New SmtpClient("yahoo.com") 
emailClient.Timeout = Int32.MaxValue 
emailClient.Send(MyMessage) 
TextBox1.Text = "Message Sent"
4

2 に答える 2

1

これを行う正しい方法は、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の宣言を使用し、ユニコードから ANSI への変換と構造体のポインターを多用します。

すべてのメール クライアントがこれをサポートしているわけではないことに注意してください。唯一の解決策は、それぞれにカスタム インターフェイスを使用することです。

于 2013-03-07T17:28:20.977 に答える
-1

使用する開発環境によって異なります。.EML ファイルを作成できるかどうかを確認します。そして、ファイルをロードする新しいプロセスを開始します。これは、メール クライアントが .EML 拡張子に関連付けられている限り機能します。

ここでは、.NET 環境の例を見つけることができます。

添付ファイルとともにデフォルトのメールクライアントを開く

于 2014-09-01T16:23:25.347 に答える