CCDOMessage是允许使用CDO发送邮件的FreeBasic类。
使用方法
先要引用库文件
#include Once "Afx/CCDOMail.inc"
' // 创建一个CCdoMessage类的实例
DIM pMsg AS CCDOMessage
' // 组态
pMsg.ConfigValue(cdoSendUsingMethod, CdoSendUsingPort)
pMsg.ConfigValue(cdoSMTPServer, "smtp.xxxxx.xxx")
pMsg.ConfigValue(cdoSMTPServerPort, 25)
pMsg.ConfigValue(cdoSMTPAuthenticate, 1)
pMsg.ConfigValue(cdoSendUserName, "xxxx@xxxx.xxx")
pMsg.ConfigValue(cdoSendPassword, "xxxxxxxx")
pMsg.ConfigValue(cdoSMTPUseSSL, 1)
pMsg.ConfigUpdate
' // 收件人姓名 - >根据需要更改
pMsg.Recipients("xxxxx@xxxxx")
' // 发件人邮件地址 - >根据需要更改
pMsg.From("xxxxx@xxxxx")
' // 主题 - >根据需要更改
pMsg.Subject("This is a sample subject")
' // 文字正文 - >根据需要更改
pMsg.TextBody("This is a sample message text")
' // 添加附件(使用绝对路径)。
' // 注意通过重复呼叫,您可以附加多个文件。
pMsg.AddAttachment ExePath & "\xxxxx.xxx"
' // 发送消息
pMsg.Send
IF pMsg.GetLastResult = S_OK THEN PRINT "Message sent" ELSE PRINT "Failure"
要使用gmail发送消息,只需更改服务器名称和服务器端口的值:
pMsg.ConfigValue(cdoSMTPServer, "smtp.gmail.com")
pMsg.ConfigValue(cdoSMTPServerPort, 465)
评论一下?