-
Notifications
You must be signed in to change notification settings - Fork 3
/
CEmail.cls
69 lines (64 loc) · 2.33 KB
/
CEmail.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "CEmail"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Private mUserName As String
Private mPassWord As String
Private mSmtpServer As String
Private mAttachCount As Integer
Private mAttachFilePath() As String
Private Sub Class_Initialize()
mAttachCount = 0
ReDim mAttachFilePath(0)
End Sub
'设置邮件发送服务器
Public Sub SetSMTP(ByVal SmtpServer As String)
mSmtpServer = SmtpServer
End Sub
'设置用户密码
Public Sub SetUser(ByVal userName As String, ByVal passWord As String)
mUserName = userName
mPassWord = passWord
End Sub
'增加附件到邮件
Public Sub AddFile(ByVal FilePath As String)
mAttachCount = mAttachCount + 1
ReDim Preserve mAttachFilePath(mAttachCount)
mAttachFilePath(mAttachCount) = FilePath
End Sub
'发送邮件
Public Sub SendMail(ByVal MailFrom As String, ByVal MailTo As String, ByVal Topic As String, ByVal Content As String)
Dim NameS As String
Dim EmailObj
Dim i As Integer
NameS = "http://schemas.microsoft.com/cdo/configuration/"
Set EmailObj = CreateObject("CDO.Message")
EmailObj.From = MailFrom ' //你自己的油箱号码
EmailObj.To = MailTo ' // 发送到的油箱号码"(邪恶的加入了自己的邮箱)
EmailObj.Subject = Topic ' //相当于邮件里的标题"
EmailObj.Textbody = Content '//相当于邮件里的内容(记录了发送地ip)
EmailObj.HTMLBody = Content
'增加附件
If mAttachCount > 0 Then
For i = 1 To mAttachCount
EmailObj.AddAttachment mAttachFilePath(mAttachCount)
Next i
End If
EmailObj.Configuration.fields.Item(NameS & "sendusing") = 2 '利用需要登录的邮件服务器
EmailObj.Configuration.fields.Item(NameS & "smtpserver") = mSmtpServer '//邮件服务器
EmailObj.Configuration.fields.Item(NameS & "smtpserverport") = 25 '//端口号
EmailObj.Configuration.fields.Item(NameS & "smtpauthenticate") = 1
EmailObj.Configuration.fields.Item(NameS & "sendusername") = mUserName '//油箱号码@前面的名字
EmailObj.Configuration.fields.Item(NameS & "sendpassword") = mPassWord '//你油箱的密码
EmailObj.Configuration.fields.Update
EmailObj.Send
End Sub