先上测试过的#include <Misc.au3>
#include <SmtpMailer.au3>
Opt("TrayAutoPause",0) ;禁止托盘暂停脚本
Opt("TrayMenuMode",0) ;隐藏托盘菜单
Dim $as_Body, $s_AttachFiles
if _Singleton("mail",1) = 0 Then
Msgbox(0,"警告","有一个程序正在运行了",3)
Exit
EndIf
$s_SmtpServer = "smtp.qq.com" ;SMTP服务器(必填)
;以下部分个人信息 就不上了 $IPPort $ssl 不要用字符串 以免出错
$s_FromName = "" ;邮件发送人(可选)
$s_FromAddress = "haomm@QQ.com" ;邮件发送者地址(必填 必须与;用户名;密码那一项所用的邮箱一致)
$s_ToAddress = "" ;收件人地址(至少填一个邮箱地址,多个邮箱地址用 ; 隔开)
$s_CcAddress = "" ;抄送地址(可选)
$s_BccAddress = "" ;密件抄送地址(可选)
$s_Username = "" ;用户名(必填)
$s_Password = "" ;密码(必填)
;以上部分个人信息 就不上了 $IPPort $ssl 不要用字符串 以免出错
$IPPort = 25;发送端口,Gmail使用的发送端口为465 (必填)
$ssl = 0 ;SSL 直接填 0 防止发不出!
$s_Subject = "测试标题" ;标题
MsgBox(4096,"确认必要信息",$s_SmtpServer&@CRLF&$s_FromName&@CRLF&$s_FromAddress&@CRLF&$s_ToAddress&@CRLF&$s_CcAddress&@CRLF&$s_BccAddress&@CRLF&$s_Username&@CRLF&$s_Password&@CRLF&$IPPort&@CRLF&$ssl)
Func sendmail()
Global $oMyRet[2]
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
$senmail = _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, $s_AttachFiles, $s_CcAddress, $s_BccAddress, $s_Username, $s_Password, $IPPort, $ssl)
If @error Then
MsgBox(0, "邮件发送失败", "错误代号:" & @error )
EndIf
EndFunc ;发送邮件过程
Func _EmptyScriptMem()
Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, _
'int', False, 'int', @AutoItPID)
Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
DllCall("kernel32.dll" , 'int', 'CloseHandle', 'int', $ai_Handle[0])
EndFunc;对脚本内存进行释放 KN007
$s_AttachFiles =FileOpenDialog ("添加附件",@WindowsDir,"图像文件 (*.jpg;*.bmp)", 1 + 4) ;测试附件
$as_Body = InputBox("输入你的邮件内容","请输入正文内容","测试内容!") ;测试正文
sendmail()
_EmptyScriptMem()
Exit
include 需要用到的 请放到 au3 include目录下#Region AutoIt3Wrapper 预编译参数(常用参数)
#AutoIt3Wrapper_Icon= ;图标,支持EXE,DLL,ICO
#AutoIt3Wrapper_OutFile= ;输出文件名
#AutoIt3Wrapper_OutFile_Type=exe ;文件类型
#AutoIt3Wrapper_Compression=4 ;压缩等级
#AutoIt3Wrapper_UseUpx=y ;使用压缩
#AutoIt3Wrapper_Res_Comment= ;注释
#AutoIt3Wrapper_Res_Description= ;详细信息
#AutoIt3Wrapper_Res_Fileversion= ;文件版本
#AutoIt3Wrapper_Res_FileVersion_AutoIncrement=p ;自动更新版本
#AutoIt3Wrapper_Res_LegalCopyright= ;版权
#AutoIt3Wrapper_Change2CUI=N ;修改输出的程序为CUI(控制台程序)
;#AutoIt3Wrapper_Res_Field=AutoIt Version|%AutoItVer% ;自定义资源段
;#AutoIt3Wrapper_Run_Tidy= ;脚本整理
;#AutoIt3Wrapper_Run_Obfuscator= ;代码迷惑
;#AutoIt3Wrapper_Run_AU3Check= ;语法检查
;#AutoIt3Wrapper_Run_Before= ;运行前
;#AutoIt3Wrapper_Run_After= ;运行后
#EndRegion AutoIt3Wrapper 预编译参数设置完成
#cs ____________________________________
Au3 版本:
脚本作者:
Email:
QQ/TM:
脚本版本:
脚本功能:
#ce _______________脚本开始_________________
#Include <file.au3>
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
Global $oMyRet[2]
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
;~ $rc = _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, $s_AttachFiles, $s_CcAddress, $s_BccAddress, $s_Username, $s_Password, $IPPort, $ssl)
;~ If @error Then
;~ MsgBox(0, "Error sending message", "Error code:" & @error & " Description:" & $rc)
;~ EndIf
;
Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Username = "", $s_Password = "",$IPPort=25, $ssl=0)
$objEmail = ObjCreate("CDO.Message")
$objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'
$objEmail.To = $s_ToAddress
Local $i_Error = 0
Local $i_Error_desciption = ""
If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress
If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress
$objEmail.Subject = $s_Subject
If StringInStr($as_Body,"<") and StringInStr($as_Body,">") Then
$objEmail.HTMLBody = $as_Body
Else
$objEmail.Textbody = $as_Body & @CRLF
EndIf
If $s_AttachFiles <> "" Then
Local $S_Files2Attach = StringSplit($s_AttachFiles, ";")
For $x = 1 To $S_Files2Attach[0]
$S_Files2Attach[$x] = _PathFull ($S_Files2Attach[$x])
If FileExists($S_Files2Attach[$x]) Then
$objEmail.AddAttachment ($S_Files2Attach[$x])
Else
$i_Error_desciption = $i_Error_desciption & @lf & 'File not found to attach: ' & $S_Files2Attach[$x]
SetError(1)
return 0
EndIf
Next
EndIf
$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer
$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort
;Authenticated SMTP
If $s_Username <> "" Then
$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username
$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password
EndIf
If $Ssl Then
$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
EndIf
;Update settings
$objEmail.Configuration.Fields.Update
; Sent the Message
$objEmail.Send
if @error then
SetError(2)
return $oMyRet[1]
EndIf
EndFunc ;==>_INetSmtpMailCom
;
;
; Com Error Handler
Func MyErrFunc()
$HexNumber = Hex($oMyError.number, 8)
$oMyRet[0] = $HexNumber
$oMyRet[1] = StringStripWS($oMyError.description,3)
ConsoleWrite("### COM Error ! Number: " & $HexNumber & " ScriptLine: " & $oMyError.scriptline & " Description:" & $oMyRet[1] & @LF)
SetError(1); something to check for when this function returns
Return
EndFunc ;==>MyErrFunc
|