|
我用这个可以发送- Sub SendTest()
- SendMail "JWH@163.com", "JWH@163.com", "你好", _
- "这是一个自动发送的问候邮件。", _
- ThisWorkbook.Path & "\try.txt"
- End Sub
- Public Sub SendMail( _
- ByVal strTo As String, _
- ByVal strCC As String, _
- ByVal strSubject As String, _
- ByVal strBody As String, _
- Optional ByVal strAttach As String)
- Dim objOutLook As Object
- Dim objMailItem As Object
- On Error GoTo errHandle
- Set objOutLook = CreateObject("Outlook.Application")
-
- Set objMailItem = objOutLook.CreateItem(0)
- With objMailItem
- .To = strTo
- .CC = strCC
- .Importance = 2
- .Subject = strSubject
- .Body = strBody
- If Len(strAttach) <> 0 Then .Attachments.Add strAttach
- .Send
- End With
- Do Until objMailItem.Sent = True
- DoEvents
- Loop
- errHandle:
- objOutLook.Quit
- Set objOutLook = Nothing
- Set objMailItem = Nothing
- End Sub
复制代码
|
|