发送文本Email:
1 | <% |
2 | Set myMail=CreateObject( "CDO.Message" ) |
3 | myMail.Subject= "Sending email with CDO" |
4 | myMail.From= "mymail@mydomain.com" |
5 | myMail. To = "someone@somedomain.com" |
6 | myMail.TextBody= "This is a message." |
7 | myMail.Send |
8 | set myMail=nothing |
9 | %> |
01 | <% |
02 | Set myMail=CreateObject( "CDO.Message" ) |
03 | myMail.Subject= "Sending email with CDO" |
04 | myMail.From= "mymail@mydomain.com" |
05 | myMail. To = "someone@somedomain.com" |
06 | myMail.Bcc= "someoneelse@somedomain.com" |
07 | myMail.Cc= "someoneelse2@somedomain.com" |
08 | myMail.TextBody= "This is a message." |
09 | myMail.Send |
10 | set myMail=nothing |
11 | %> |
1 | <% |
2 | Set myMail=CreateObject( "CDO.Message" ) |
3 | myMail.Subject= "Sending email with CDO" |
4 | myMail.From= "mymail@mydomain.com" |
5 | myMail. To = "someone@somedomain.com" |
6 | myMail.HTMLBody = "<h1>This is a message.</h1>" |
7 | myMail.Send |
8 | set myMail=nothing |
9 | %> |
1 | <% |
2 | Set myMail=CreateObject( "CDO.Message" ) |
3 | myMail.Subject= "Sending email with CDO" |
4 | myMail.From= "mymail@mydomain.com" |
5 | myMail. To = "someone@somedomain.com" |
6 | myMail.CreateMHTMLBody "http://www.w3schools.com/asp/" |
7 | myMail.Send |
8 | set myMail=nothing |
9 | %> |
1 | <% |
2 | Set myMail=CreateObject( "CDO.Message" ) |
3 | myMail.Subject= "Sending email with CDO" |
4 | myMail.From= "mymail@mydomain.com" |
5 | myMail. To = "someone@somedomain.com" |
6 | myMail.CreateMHTMLBody "file://c:/mydocuments/test.htm" |
7 | myMail.Send |
8 | set myMail=nothing |
9 | %> |
01 | <% |
02 | Set myMail=CreateObject( "CDO.Message" ) |
03 | myMail.Subject= "Sending email with CDO" |
04 | myMail.From= "mymail@mydomain.com" |
05 | myMail. To = "someone@somedomain.com" |
06 | myMail.TextBody= "This is a message." |
07 | myMail.AddAttachment "c:\mydocuments\test.txt" '重复多次即可添加多个文件。 |
08 | myMail.Send |
09 | set myMail=nothing |
10 | %> |
01 | <% |
02 | Set myMail=CreateObject( "CDO.Message" ) |
03 | myMail.Subject= "Sending email with CDO" |
04 | myMail.From= "mymail@mydomain.com" |
05 | myMail. To = "someone@somedomain.com" |
06 | myMail.TextBody= "This is a message." |
07 | myMail.Configuration.Fields.Item _ |
09 | 'Name or IP of remote SMTP server |
10 | myMail.Configuration.Fields.Item _ |
12 | = "smtp.server.com" |
13 | 'Server port |
14 | myMail.Configuration.Fields.Item _ |
16 | =25 |
17 | myMail.Configuration.Fields.Update |
18 | myMail.Send |
19 | set myMail=nothing |
20 | %> |
01 | Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory. |
02 | Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network). |
03 | |
04 | Const cdoAnonymous = 0 'Do not authenticate |
05 | Const cdoBasic = 1 'basic (clear-text) authentication |
06 | Const cdoNTLM = 2 'NTLM |
07 | |
08 | Set objMessage = CreateObject( "CDO.Message" ) |
09 | objMessage.Subject = "Example CDO Message" |
10 | objMessage.From = "" "Me" " <me@my.com>" |
11 | objMessage. To = "test@paulsadowski.com" |
12 | objMessage.TextBody = "This is some sample message text.." & vbCRLF & "It was sent using SMTP authentication." |
13 | |
14 | objMessage.Configuration.Fields.Item _ |
16 | |
17 | 'Name or IP of Remote SMTP Server |
18 | objMessage.Configuration.Fields.Item _ |
19 | ( "http://schemas.microsoft.com/cdo/configuration/smtpserver" ) = "mail.your.com" |
20 | |
21 | '验证方式, NONE, Basic (Base64 encoded), NTLM |
22 | objMessage.Configuration.Fields.Item _ |
23 | ( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ) = cdoBasic |
24 | |
25 | 'SMTP 服务器的用户名 |
26 | objMessage.Configuration.Fields.Item _ |
27 | ( "http://schemas.microsoft.com/cdo/configuration/sendusername" ) = "youruserid" |
28 | |
29 | 'SMTP 服务器的密码 |
30 | objMessage.Configuration.Fields.Item _ |
31 | ( "http://schemas.microsoft.com/cdo/configuration/sendpassword" ) = "yourpassword" |
32 | |
33 | 'Server端口(通常为25) |
34 | objMessage.Configuration.Fields.Item _ |
36 | |
37 | '是否使用SSL连接(False 或 True) |
38 | objMessage.Configuration.Fields.Item _ |
40 | |
41 | '连接smtp的超时时间,单位为秒 |
42 | objMessage.Configuration.Fields.Item _ |
44 | |
45 | objMessage.Configuration.Fields.Update |
46 | |
47 | objMessage.Send |
交付处置通知请求。为了使用的传递状态通知(返回
收据和交付处置的要求),我们需要创建一个引用到CDO的配置
除了CDO Message对象的对象,并设置小数目的属性。你必须
使用cdoSendUsingPort(网络连接),而不是SMTP服务器的拾取目录
(cdoSendUsingPickup)。
01 | Const cdoSendUsingPickup = 1 |
02 | Const cdoSendUsingPort = 2 '如果使用发送通知,必须使用这个。Const cdoAnonymous = 0 |
03 | Const cdoBasic = 1 ' clear text |
04 | Const cdoNTLM = 2 'NTLM |
05 | '发送状态通知 |
06 | Const cdoDSNDefault = 0 'None |
07 | Const cdoDSNNever = 1 'None |
08 | Const cdoDSNFailure = 2 'Failure |
09 | Const cdoDSNSuccess = 4 'Success |
10 | Const cdoDSNDelay = 8 'Delay |
11 | Const cdoDSNSuccessFailOrDelay = 14 'Success, failure or delay |
12 | |
13 | set objMsg = CreateObject( "CDO.Message" ) |
14 | set objConf = CreateObject( "CDO.Configuration" ) |
15 | |
16 | Set objFlds = objConf.Fields |
17 | With objFlds |
18 | .Item( "http://schemas.microsoft.com/cdo/configuration/sendusing" ) = cdoSendUsingPort |
19 | .Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver" ) = "mail.yourhost.com" |
20 | .Item( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ) = cdoBasic |
21 | .Item( "http://schemas.microsoft.com/cdo/configuration/sendusername" ) = "your-username" |
22 | .Item( "http://schemas.microsoft.com/cdo/configuration/sendpassword" ) = "your-password" |
23 | .Update |
24 | End With |
25 | |
26 | strBody = "This is a sample message." & vbCRLF |
27 | strBody = strBody & "It was sent using CDO." & vbCRLF |
28 | |
29 | With objMsg |
30 | Set .Configuration = objConf |
31 | . To = "test@paulsadowski.com" |
32 | .From = "me@my.com" |
33 | .Subject = "This is a CDO test message" |
34 | .TextBody = strBody |
35 | 'use .HTMLBody to send HTML email. |
36 | .Addattachment "c:\temp\Scripty.zip" |
37 | .Fields( "urn:schemas:mailheader:disposition-notification-to" ) = "me@my.com" |
38 | .Fields( "urn:schemas:mailheader:return-receipt-to" ) = "me@my.com" |
39 | .DSNOptions = cdoDSNSuccessFailOrDelay |
40 | .Fields.update |
41 | .Send |
42 | End With |