Option Explicit Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _ (ByVal hwnd As Long, _ ByVal lpOperation As String, _ ByVal lpFile As String, _ ByVal lpParameters As String, _ ByVal lpDirectory As String, _ ByVal nShowCmd As Long) As Long Private Const SW_SHOW = 5 Private Sub Command1_Click() Call ShellExecute(Me.hwnd, _ "open", _ "[email protected]?subject=MySubject&Attach=""c:\test.txt""", _ vbNullString, _ vbNullString, _ SW_SHOW) End Sub
(ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long Private Const SW_SHOW = 5 Private Sub Command1_Click()
Call ShellExecute(Me.hwnd, _
"open", _
"[email protected]?subject=MySubject&Attach=""c:\test.txt""", _
vbNullString, _
vbNullString, _
SW_SHOW)
End Sub
'构造信
Private Sub GenMail(bAttachment As Boolean)
Dim fnum As Integer, FAttin As Integer
Dim strLine As String
strSendName = txtSName.Text
strReceiveName = txtRName.Text
strFromMail = txtFrom.Text
strToMail = txtTo.Text
m_Date = Format(Date, "Ddd") & ", " & Format(Date, "dd Mmm YYYY") & " " & Format(Time, "hh:mm:ss") & "" & " -0600"
strSubject = txtSubject.Text
strContent = txtContent.Text
fnum = FreeFile()
Open App.Path & "\mail.tmp" For Output As fnum
'¹¹ÔìÐżþ±êÌâ×Ö¶Î
Print #fnum, "From:" & Chr(32) & strSendName
Print #fnum, "Date:" & Chr(32) & m_Date
Print #fnum, "X-Mailer: BigAnt Smtp Mailer V1.0"
Print #fnum, "To:" & Chr(32) & strReceiveName
Print #fnum, "Subject:" & Chr(32) & strSubject
If bAttachment = False Then
Print #fnum, ""
Print #fnum, strContent
Exit Sub
End If
Print #fnum, "MIME-Version: 1.0"
Print #fnum, "Content-type:multipart/mixed;"
Print #fnum, " boundary =""----=_NextPart_000_000A_01BF9F1A"""
Print #fnum, ""
'ÊéдÐżþµÄÕýÎÄÄÚÈÝ
Print #fnum, "--" & "----=_NextPart_000_000A_01BF9F1A"
Print #fnum, "Content-Type: text/plain;"
Print #fnum, " Charset = ""gb2312"""
Print #fnum, "Content-Transfer-Encoding: 8bit"
Print #fnum, ""
Print #fnum, strContent
'¸½¼þÄÚÈÝ
Dim i As Integer
For i = 0 To cobAtt.ListCount - 1
Base64Encode cobAtt.List(i), App.Path & "\attachment" & i & ".tmp"
Print #fnum, "--" & "----=_NextPart_000_000A_01BF9F1A"
Print #fnum, "Content-Type: Application/octet-stream"
Print #fnum, " name=" & cobAtt.List(i)
Print #fnum, "Content-Transfer-Encoding: base64"
Print #fnum, "Content-Disposition: attachment;"
Print #fnum, " FileName=" & cobAtt.List(i)
Print #fnum, ""
FAttin = FreeFile
Open App.Path & "\attachment" & i & ".tmp" For Input As #FAttin
While Not EOF(FAttin)
Line Input #FAttin, strLine
Print #fnum, strLine
Wend
Close FAttin
Next i
Print #fnum, "--" & "----=_NextPart_000_000A_01BF9F1A" & "--"
Close fnum
End Sub