function和function变量之间的通信如何转换
如题,下面代码去掉function dog()之后就能正常收发邮件,小弟没学过其他编程,百度了半个月也搞不明白他们之间的关系。我是想要把下面邮件的UDF转到其他function,然后加变量直接发送邮件。请问这样要怎么实现呀?
#include <SmtpMailer.au3>
$ID = @ComputerName
Func dog()
$MailTitle = "日志" & $
$MailBody = $MailTitle
$recipients = "Example@qq.com"
$MailAtt = ""
$recipientCC = ""
SendMail($recipients, $MailTitle, $MailBody, $MailAtt, $recipientCC)
EndFunc
Func SendMail($recipients, $MailTitle, $MailBody, $MailAtt, $recipientCC)
$SmtpServer = "smtp.mxhichina.com" ; SMTP服务器address for the smtp-server to use - REQUIRED
$FromName = "" ; 发送人name from who the email was sent
$FromAddress = "Example@qq.com" ; 发送人地址address from where the mail should come - 139mail REQUIRED
$ToAddress = $recipients ; 收件人地址destination address of the email - REQUIRED
$Subject = $MailTitle ; 邮件标题subject from the email - can be anything you want it to be
$Body = $MailBody ; 邮件正文the messagebody from the mail - can be left blank but then you get a blank mail
$AttachFiles = $MailAtt ; 附件链接the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed
$CcAddress = $recipientCC ; 抄送地址address for cc - leave blank if not needed
$BccAddress = "" ; 秘密抄送地址address for bcc - leave blank if not needed
$Importance = "Normal" ; 邮件重要性Send message priority: "High", "Normal", "Low"
$Username = "Example@qq.com" ; 用户名username for the account used from where the mail gets sent - REQUIRED
$Password = "########" ; 密码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
Global $oMyRet
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
$rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password)
If @error Then
MsgBox(0, "Error sending message", "Error code:" & @error & "Description:" & $rc)
EndIf
Return $rc
EndFunc #include <SmtpMailer.au3>
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
dog(@ComputerName)
Func dog($ID)
Local $MailTitle = "日志" & $ID
Local $MailBody = $MailTitle
Local $recipients = "Example@qq.com"
SendMail($recipients, $MailTitle, $MailBody, '', '')
EndFunc ;==>dog
Func SendMail($recipients, $MailTitle, $MailBody, $MailAtt, $recipientCC)
Local $SmtpServer = "smtp.mxhichina.com" ; SMTP服务器address for the smtp-server to use - REQUIRED
Local $FromName = "" ; 发送人name from who the email was sent
Local $FromAddress = "Example@qq.com" ; 发送人地址address from where the mail should come - 139mail REQUIRED
Local $ToAddress = $recipients ; 收件人地址destination address of the email - REQUIRED
Local $Subject = $MailTitle ; 邮件标题subject from the email - can be anything you want it to be
Local $Body = $MailBody ; 邮件正文the messagebody from the mail - can be left blank but then you get a blank mail
Local $AttachFiles = $MailAtt ; 附件链接the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed
Local $CcAddress = $recipientCC ; 抄送地址address for cc - leave blank if not needed
Local $BccAddress = "" ; 秘密抄送地址address for bcc - leave blank if not needed
Local $Importance = "Normal" ; 邮件重要性Send message priority: "High", "Normal", "Low"
Local $Username = "Example@qq.com" ; 用户名username for the account used from where the mail gets sent - REQUIRED
Local $Password = "########" ; 密码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
Local $rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password)
If @error Then
MsgBox(0, "Error sending message", "Error code:" & @error & "Description:" & $rc)
Return SetError(1, 0, 0)
EndIf
Return $rc
EndFunc ;==>SendMail
Func MyErrFunc()
Local $sErrInfo = "ErrSource: " & $oMyError.Source & @LF & "DESC: " & $oMyError.Description
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sErrInfo = ' & $sErrInfo & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
EndFunc ;==>MyErrFunc 这是自定义函数的语法问题,可以在帮助文档中索引输入 “Func” 就能找到相关知识 这样来理解,一个完整的脚本结构,分为二个部分,一部分是func .... endfunc 及其之间的内容,我姑且叫它为一个udf函数,可能这个udf函数有多个.另一部份就是udf函数之外的内容,我姑且叫它为根.
脚本代码运行从根开始逐行执行.执行过程中有call udf函数,那么执行这个udf函数之后返回到call后继续执行根内容,直到结束.如果脚本只有udf函数,没有根,那么不会执行任何代码.
咱们回到你发出的代码,当然,代码其实有错误,A版已经给你改正了.
因为你的脚本根代码中没有调用UDF函数,因此,声明的二个函数都不会调用.也不会达到预期的效果
执行流程看下图
感谢A神的帮助和回答,我查看了相关的帮助文档,FuncName ( $Functionvariable ) :A variable containing a Function whose name you want to retrieve.
我多练练这里面的关系和位置。万分感谢!:face (38):
感谢A神的帮助和回答,我查看了相关的帮助文档,FuncName ( $Functionvariable ) :A variable containing a Function whose name you want to retrieve.
我多练练这里面的关系和位置。万分感谢!:face (38):
tubaba 发表于 2021-12-2 16:35
这样来理解,一个完整的脚本结构,分为二个部分,一部分是func .... endfunc 及其之间的内容,我姑且叫它为 ...
感谢tubaba的耐心指导,原来我是一直想着如何把外面的变量输入到func里面去,不懂如何调用UDF函数。如果不是A版的正确代码和你的指引流程是真的不理解,当时我是想把变量放到func括号旁让后再在外面输入变量的值来输出,以为这样func就能知道这个变量😂,现在才知道UDF函数是这样调用变量值的。Func(发件人,标题,文本)不输入的就单引号空开。调用出来就直接funcname(发件人,标题,‘’)输出。
万分感谢!!
页:
[1]