[已解决]发送邮件的UDF或脚本
本帖最后由 fuinei 于 2011-10-10 23:36 编辑各位好,请问如需实现ping某个IP地址不通的情况下发送邮件给某几个人可以如何实现呢? 本帖最后由 zsken 于 2011-9-27 08:48 编辑
; 请先注册 jmail.dll, 最好是用JMail4.4_PRO,因为这个版本有POP3功能,方便以后收信息。
; 如果只是用来发送,其它版本都可以。
; 为了脚本的健壮性,最好处理COM错误, 如 ObjEvent("AutoIt.Error", "AutoCOMErrFunc")
; 如果测试用的也是QQ邮件请开能SMTP功能,其它如163等默认都是开通的
Local $msg = ObjCreate ("JMail.Message")
If IsObj($msg) Then
$msg.Charset = "gb2312"
$msg.Silent = true
$msg.Priority = 3
$msg.MailServerUserName = "1234567" ; SMTP验证用户名
$msg.MailServerPassword = "7654321" ; SMTP验证密码
$msg.From = "1234567@qq.com" ; 发件人地址
$msg.FromName = "1234567" ; 发件人名称
$msg.AddRecipient("1234567@qq.com", "1234567") ; 收件人信息
$msg.Subject = "测试" ; 邮件标题
$msg.Body = "这是测试邮件" & @CRLF ; 邮件内容第1行
$msg.AppendText("这是附加的信息") ; 邮件内容第n行
If $msg.Send("smtp.qq.com") Then
MsgBox(0, "", "发送成功")
Else
MsgBox(0, "", "发送失败")
EndIf
Else
MsgBox(0, "", "ObjCreate Jmail.Message失败")
EndIf
使用Jmail4.5free版本已测试成功,谢谢2楼的指导
请问你上传的pro版本是否是全功能的呢?官网是收费的哦 楼上的支持带附件吗? 请问zsken 兄提供的jmail4.4Pro.rar是否为全功能无限制版本呢? 回复 4# menfan1
搜索
SmtpMailer.au3
支持附件的 顶六楼的,我测试过,完全可以用,不需要jmail.dll
二楼的也可以用 Jmail.dll测试可用,官网也有example和说明文档,请问楼上的兄弟可提供一个smtpmailer.au3的使用范例吗? 网上找的;~ Smtp Mailer
;http://www.autoitscript.com/forum/index.php?showtopic=23860&st=0
#Include<file.au3>
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
;##################################
; Include
;##################################
#Include<file.au3>
;##################################
; Variables
;##################################
$s_SmtpServer = "smtp.gmail.com" ; smtp服务器 address for the smtp-server to use - REQUIRED
$s_FromName = "www.yidabu.com" ; 邮件发送人 name from who the email was sent
$s_FromAddress = "your@gmail.com" ; 邮件发送者地址address from where the mail should come
$s_ToAddress = "your@gmail.com" ; 邮件发送给谁 destination address of the email - REQUIRED
$s_Subject = "bbs.yidabu.com" ;邮件标题 subject from the email - can be anything you want it to be
$as_Body = "autoit论坛" & @CRLF & _
"http://bbs.yidabu.com/forum-2-1.html" ; 邮件正文the messagebody from the mail - can be left blank but then you get a blank mail
$s_AttachFiles = "" ; 附件地址 the file you want to attach- leave blank if not needed
$s_CcAddress = "" ; address for cc - leave blank if not needed
$s_BccAddress = "" ; address for bcc - leave blank if not needed
$s_Username = "yidabu" ;用户名 username for the account used from where the mail gets sent - REQUIRED
$s_Password = "www.yidabu.com" ; 密码password for the account used from where the mail gets sent - REQUIRED
$IPPort = 25 ; 发送端口 port used for sending the mail
$ssl = 0 ; 安全连接 enables/disables secure socket layer sending - put to 1 if using httpS
;~ $IPPort=465 ; yidabu.com提示:Gmail使用的发送端口
;~ $ssl=1 ; yidabu.com提示:Gmail要启用安全连接
;##################################
; Script
;##################################
Global $oMyRet
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
$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
EndIf
EndFunc ;==>_INetSmtpMailCom
;
;
; Com Error Handler
Func MyErrFunc()
$HexNumber = Hex($oMyError.number, 8)
$oMyRet = $HexNumber
$oMyRet = StringStripWS($oMyError.description,3)
ConsoleWrite("### COM Error ! Number: " & $HexNumber & " ScriptLine: " & $oMyError.scriptline & " Description:" & $oMyRet & @LF)
SetError(1); something to check for when this function returns
Return
EndFunc ;==>MyErrFunc 上述的smtpmailer代码我也找到了,不知道有没有类似于2楼兄弟给出的简单示范或使用说明呢? 代码中有mirosoft网站的Link,请问在计算机无法联网的情况下是否部分功能即使有内部的smtp服务器也无法正常使用呢? 学习一下邮件发送的代码 论坛有SmtpMailer.au3 附件 抄送 暗抄都支持~!~ 个人感觉很不错~提问的时候先搜搜吧~ 研究了一下原来smtpmailer.au3是使用cdo.message发送邮件的,也测试成功了。 同求jamail 发送邮件
页:
[1]
2