本帖最后由 kk_lee69 于 2011-10-22 13:50 编辑
回复 3# devil3380
#Region ;**** 參數創建於 ACNWrapper_GUI ****
DIM $MDBSpath=@ScriptDir & "\技術通報資料庫.mdb"
DIM $Txthtm = @ScriptDir&"\TXT.htm"
DIM $Namehtm = @ScriptDir&"\name.htm"
DIM $ErrorMailList = "yanjan13@yanjan.com.tw;mann@ms2.hinet.net;yan.jan@msa.hinet.net"
;#include "SmtpMail.au3"
#include<array.au3>
#Include <file.au3>
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
Global $oMyRet[2]
;~ $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
;
;郵件配置
$s_SmtpServer = "smtp.gmail.com" ;SMTP伺服器
$s_FromName = "研展資訊技術通告" ;郵件發送人
$s_FromAddress = "chit357@gmail.com" ;郵件發送者地址
$s_ToAddress = "kevin@puretorq.com" ;收件人地址
$s_Subject = "研展資訊--正航技術通告--" ;郵件標題
$as_Body = "正航技術通告 " ;郵件正文 @CRLF 為分行符號
$s_AttachFiles = "" ;附件位置 【多個檔案 請用 ; 分號隔開。】
$s_CcAddress = "" ;抄送地址
$s_BccAddress = "" ;密件抄送地址
$s_Username = "t357" ;用戶名
$s_Password = "357i" ;密碼
$IPPort = 465 ;發送埠,Gmail使用的發送埠為465 一般為25
$ssl = 1 ;GMAIL 要用SSL=1 一般不啟用 SSL=0
If FileExists($MDBSpath) Then
Else
MsgBox(0,"資料庫檔案不存在","技術通報資料庫.MDB 檔案不存在..........請洽詢 研展資訊"&@CRLF&"請按確定離開程式...............")
EXIT
EndIf
$conn = ObjCreate("ADODB.Connection")
$RS = ObjCreate("ADODB.Recordset")
$conn.Open ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=技術通報資料庫.mdb");主機名IP127.0.0.1,UID=用戶,PWD=密碼,database=資料庫名 ※
$RS.ActiveConnection = $conn;好像是主連接,這個好像比較重要
$RS.open ("select * from 系統設定");
While (Not $RS.eof And Not $RS.bof);迴圈讀表
;MsgBox(0, "欄位一", $RS.Fields (0).value,5);顯示第一個欄位 資料
;MsgBox(0, "欄位二", $RS.Fields (4).value);顯示第二個欄位 資料
;郵件配置
If $RS.Fields(0).value="A01" Then $s_SmtpServer = $RS.Fields(2).value ;SMTP伺服器
If $RS.Fields(0).value="A02" Then $s_FromName = $RS.Fields(2).value ;郵件發送人
If $RS.Fields(0).value="A03" Then $s_FromAddress = $RS.Fields(2).value ;郵件發送者地址
If $RS.Fields(0).value="A04" Then $s_Subject = $RS.Fields(2).value ;郵件標題
If $RS.Fields(0).value="A05" Then $s_Username = $RS.Fields(2).value ;用戶名
If $RS.Fields(0).value="A06" Then $s_Password = $RS.Fields(2).value ;密碼
If $RS.Fields(0).value="A07" Then $IPPort = $RS.Fields(2).value ;發送埠,Gmail使用的發送埠為465 一般為25
If $RS.Fields(0).value="A08" Then $ssl = $RS.Fields(2).value ;GMAIL 要用SSL=1 一般不啟用 SSL=0
$RS.movenext;跳出迴圈
WEnd;結束迴圈讀表
$RS.close;關閉數據分表
sendmail ()
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
;$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 0
;$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
;$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/SMTPConnectionTimeout") = 100
;objConfig.Fields("http://schemas.microsoft.com/cdo/configuration/languagecode") = "0x0804"
;$objMail.BodyPart.Charset="UTF-8"
;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()
Local $errstr="COM 錯誤訊息 !!!"& @CRLF & @CRLF & _
"錯誤描述:" & @TAB & $oMyError.description & @CRLF & _
"WIN 錯誤描述:" & @TAB & $oMyError.windescription & @CRLF & _
"錯誤代碼:" & @TAB & hex($oMyError.number,8) & @CRLF & _
"上次 DLL 錯誤:" & @TAB & $oMyError.lastdllerror & @CRLF & _
"錯誤腳本行:" & @TAB & $oMyError.scriptline & @CRLF & _
"錯誤來源:" & @TAB & $oMyError.source & @CRLF & _
"錯誤幫助檔:" & @TAB & $oMyError.helpfile & @CRLF & _
"錯誤幫助功能表:" & @TAB & $oMyError.helpcontext & @CRLF
FileWrite(@ScriptDir&"\ErrorLog.log",@YEAR&@MON&@MDAY&" "&@HOUR&":"&@MIN&":"&@SEC&" ..... "&$errstr&@CRLF&@CRLF&@CRLF)
Msgbox(0,"AutoIt COM 錯誤",$errstr,30)
Local $err = $oMyError.number
If $err = 0 Then $err = -1
$g_eventerror = $err ; to check for after this function returns
Endfunc
Func sendmail ()
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 & " 描述:" & $rc)
EndIf
EndFunc
重點是 用上面的 GMAIL 一切正常 用自己的 公司的主機 就會出錯誤.................
MAIL 代碼 部分應該都是一樣的...............重點在於 我也知道這是可以跑的.....但是我用公司的主機就是不行....用朋友公司的也不行....不知道為何?? |