VisualBasic使用CDO发送SSL加密邮件【我TM还是太年轻了】

首先,在工程里引用一个COM:Microsoft CDO for Windows 2000 Library

接着他应该会自动imports俩组件,如果没有的话你自己写:

Imports CDO
Imports ADODB

代码:

    Private Sub SendTestCDOMessage()
        Dim cdoObj As Object
        cdoObj = CreateObject("cdo.Message")


        ' TODO: 使用本地SMTP服务器
        'cdo.Configuration.Fields.item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1


        ' 设置外部SMTP服务器
        cdoObj.Configuration.Fields.item _
            ("http://schemas.microsoft.com/cdo/configuration/sendusing") _
            = CDO.CdoSendUsing.cdoSendUsingPort


        cdoObj.Configuration.Fields.item _
            ("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
            = "smtp.163.com"


        cdoObj.Configuration.Fields.item _
            ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") _
            = 465


        cdoObj.Configuration.Fields.item _
            ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") _
            = CDO.CdoProtocolsAuthentication.cdoB
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
以下是使用 Classic ASP 和 SSL 发送电子邮件的示例代码: ``` <% Dim objMail Set objMail = Server.CreateObject("CDO.Message") ' Set up the email configuration objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com" objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "[email protected]" objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "your_password" objMail.Configuration.Fields.Update ' Set up the email content objMail.To = "[email protected]" objMail.From = "[email protected]" objMail.Subject = "Test Email" objMail.TextBody = "This is a test email sent using SSL." ' Send the email On Error Resume Next objMail.Send If Err.Number = 0 Then Response.Write "Email sent successfully." Else Response.Write "An error occurred: " & Err.Description End If Set objMail = Nothing %> ``` 请注意,您需要将上面的代码中的以下行替换为您自己的电子邮件地址和密码: ``` objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "[email protected]" objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "your_password" objMail.To = "[email protected]" objMail.From = "[email protected]" ``` 此外,您需要将 SMTP 服务器和端口设置为您使用电子邮件服务的设置。在上面的示例中,我们使用 Gmail 的 SMTP 服务器和端口。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值