أرسل بريدًا إلكترونيًا مع Autoit
سؤال
كيف ترسل بريدًا إلكترونيًا باستخدام Autoit؟ فقط بحاجة إلى مثال نظيف وشرح ، يحتوي على:
- إلى
- من
- موضوعات
- رسالة
المحلول
هناك طريقتان رئيسيتان للذهاب مع رمز مدمج ، _inetmail () أو _inetsmtpmail ()
فيما يلي أمثلة رمز بسيطة من ملف المساعدة. إذا كان لديك أي أسئلة محددة حول كيفية عملها أو كيفية تنفيذها غير مغطى بملف المساعدة ، فيرجى ترك تعليق.
في رأيي ، يكون مسار _inetsmtpmail () أكثر منطقية. فيما يلي بعض كود مثال عليه.
#include <INet.au3>
$s_SmtpServer = "mysmtpserver.com.au"
$s_FromName = "My Name"
$s_FromAddress = "From eMail Address"
$s_ToAddress = "To eMail Address"
$s_Subject = "My Test UDF"
Dim $as_Body[2]
$as_Body[0] = "Testing the new email udf"
$as_Body[1] = "Second Line"
$Response = _INetSmtpMail ($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body)
$err = @error
If $Response = 1 Then
MsgBox(0, "Success!", "Mail sent")
Else
MsgBox(0, "Error!", "Mail failed with error code " & $err)
EndIf
طريقة _InetMail () باستخدام عميل البريد المضمّن المسجل مع Windows.
#include <INet.au3>
$Address = InputBox('Address', 'Enter the E-Mail address to send message to')
$Subject = InputBox('Subject', 'Enter a subject for the E-Mail')
$Body = InputBox('Body', 'Enter the body (message) of the E-Mail')
MsgBox(0,'E-Mail has been opened','The E-Mail has been opened and process identifier for the E-Mail client is ' & _INetMail($address, $subject, $body))
نصائح أخرى
إذا كنت ترغب في إرسال بريد إلكتروني باستخدام Autoit ، فستختار طريقة Microsoft CDO. لا تستخدم أتمتة بريد العميل (Outlook ، Thunderbird أو آخر). ميزة مبدأ CDO ، هل لا يعتمد على برنامج بريد العميل الذي تستخدمه. يعتمد فقط على خادم SMTP.
يمكنك استخدام الوظيفة _inetsmtpmail في المكتبة Autoit inet.au3. ولكن إذا كنت تريد التحكم في أي شيء ، فيمكنك استخدام هذه الوظيفة المحددة للمستخدم _inetsmtpmail أقل :
ملف UDF Autoit: udf_smtp_email.au3
;==============================================================================================================
; Description : Send an email with a SMTP server by Microsoft CDO technology
; Parametere : $s_SmtpServer
; $s_FromName
; $s_FromAddress
; $s_ToAddress
; $s_Subject
; $as_Body
; $s_AttachFiles (path file to join)
; $s_CcAddress
; $s_BccAddress
; $s_Username
; $s_Password
; $IPPort
; $ssl
; Return : On success none
; On error code+msg
;==============================================================================================================
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)
Local $objEmail = ObjCreate("CDO.Message")
Local $i_Error = 0
Local $i_Error_desciption = ""
$objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'
$objEmail.To = $s_ToAddress
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
;===========================================================================================================
إليك متغير ما وصفه Copas. يجب أن ترسل لك تلقائيا
#include <INet.au3>
$time1 = _NowTime()
$Address = "" ;To Address
$Subject = ""
$Body = ""
_INetMail($address, $subject, $body)
Local $hWnd = WinWait("[CLASS:rctrl_renwnd32]", "", 2) ;Works with Outlook 2013. Class might vary. Use the info tool to be sure. Eg I seriously doubt it will be the same with something like thunderbird.
ControlClick($hWnd, "", "Button1")