asp使用CDO.Message组件发邮件示例

asp使用CDO.Message组件发邮件示例-远程Server需要身份验证

    Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory. 
    Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network). 
     
    Const cdoAnonymous = 0 'Do not authenticate
    Const cdoBasic = 1 'basic (clear-text) authentication
    Const cdoNTLM = 2 'NTLM
     
    Set objMessage = CreateObject("CDO.Message") 
    objMessage.Subject = "Example CDO Message" 
    objMessage.From = """Me"" <me@my.com>" 
    objMessage.To = "test@paulsadowski.com" 
    objMessage.TextBody = "This is some sample message text.." & vbCRLF & "It was sent using SMTP authentication."
     
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
     
    'Name or IP of Remote SMTP Server
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.your.com"
     
    '验证方式, NONE, Basic (Base64 encoded), NTLM
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
     
    'SMTP 服务器的用户名
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "youruserid"
     
    'SMTP 服务器的密码
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "yourpassword"
     
    'Server端口(通常为25)
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
     
    '是否使用SSL连接(False 或 True)
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
     
    '连接smtp的超时时间,单位为秒
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
     
    objMessage.Configuration.Fields.Update
     
    objMessage.Send

asp使用CDO.Message组件发邮件示例-发送对文件附件和回执,并与远程服务器的身份验证

    Const cdoSendUsingPickup = 1 
    Const cdoSendUsingPort = 2 '如果使用发送通知,必须使用这个。Const cdoAnonymous = 0
    Const cdoBasic = 1 ' clear text
    Const cdoNTLM = 2 'NTLM
    '发送状态通知
    Const cdoDSNDefault = 0 'None
    Const cdoDSNNever = 1 'None
    Const cdoDSNFailure = 2 'Failure
    Const cdoDSNSuccess = 4 'Success
    Const cdoDSNDelay = 8 'Delay
    Const cdoDSNSuccessFailOrDelay = 14 'Success, failure or delay
     
    set objMsg = CreateObject("CDO.Message")
    set objConf = CreateObject("CDO.Configuration")
     
    Set objFlds = objConf.Fields
    With objFlds
       .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
       .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.yourhost.com"
       .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
       .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "your-username"
       .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "your-password"
       .Update
    End With
     
    strBody = "This is a sample message." & vbCRLF
    strBody = strBody & "It was sent using CDO." & vbCRLF
     
    With objMsg
       Set .Configuration = objConf
       .To = "test@paulsadowski.com" 
       .From = "me@my.com"
       .Subject = "This is a CDO test message"
       .TextBody = strBody
        'use .HTMLBody to send HTML email.
       .Addattachment "c:\temp\Scripty.zip"
       .Fields("urn:schemas:mailheader:disposition-notification-to") = "me@my.com"
       .Fields("urn:schemas:mailheader:return-receipt-to") = "me@my.com" 
       .DSNOptions = cdoDSNSuccessFailOrDelay
       .Fields.update
       .Send
    End With

 

加支付宝好友偷能量挖...


原创文章,转载请注明出处:asp使用CDO.Message组件发邮件示例

评论(0)Web开发网
阅读(456)喜欢(0)Asp/VBScript