微剋多資訊

 找回密碼
 註冊

Sign in with google

Google帳號登入

搜索

簽到天數: 189

該用戶今日未簽到

升級   100%

跳轉到指定樓層
主題
發表於 2016-9-21 12:35 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
本帖最後由 gary8349 於 2016-9-21 12:36 編輯

AU3 寄送Gmail信件 無法成功
請問要如何在不啟用安全性較低的應用程式存取權的前提下達成?
(如果啟用是可以成功的)
感恩~




網上找到的代碼稍稍修改成gmail的
  1. #include <file.au3>
  2. Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
  3. Global $oMyRet[2]
  4. Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

  5. 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)
  6.         $objEmail = ObjCreate("CDO.Message")
  7.         $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'
  8.         $objEmail.To = $s_ToAddress
  9.         Local $i_Error = 0
  10.         Local $i_Error_desciption = ""
  11.         If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress
  12.         If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress
  13.         $objEmail.Subject = $s_Subject
  14.         If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then
  15.                 $objEmail.HTMLBody = $as_Body

  16.         Else
  17.                 $objEmail.Textbody = $as_Body & @CRLF
  18.         EndIf
  19.         If $s_AttachFiles <> "" Then
  20.                 Local $S_Files2Attach = StringSplit($s_AttachFiles, ";")
  21.                 For $x = 1 To $S_Files2Attach[0]
  22.                         $S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x])
  23.                         If FileExists($S_Files2Attach[$x]) Then
  24.                                 $objEmail.AddAttachment($S_Files2Attach[$x])
  25.                         Else
  26.                                 $i_Error_desciption = $i_Error_desciption & @LF & 'File not found to attach: ' & $S_Files2Attach[$x]
  27.                                 SetError(1)
  28.                                 Return 0
  29.                         EndIf
  30.                 Next
  31.         EndIf
  32.         $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  33.         $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer
  34.         $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort
  35.         ;Authenticated SMTP
  36.         If $s_Username <> "" Then
  37.                 $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
  38.                 $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username
  39.                 $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password
  40.         EndIf
  41.         If $ssl Then
  42.                 $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
  43.         EndIf
  44.         ;Update settings
  45.         $objEmail.Configuration.Fields.Update
  46.         ; Sent the Message
  47.         $objEmail.Send
  48.         If @error Then
  49.                 SetError(2)
  50.                 Return $oMyRet[1]
  51.         EndIf
  52. EndFunc   ;==>_INetSmtpMailCom

  53. Func MyErrFunc()
  54.         $HexNumber = Hex($oMyError.number, 8)
  55.         $oMyRet[0] = $HexNumber
  56.         $oMyRet[1] = StringStripWS($oMyError.description, 3)
  57.         ConsoleWrite("### COM Error !    Number: " & $HexNumber & "    ScriptLine: " & $oMyError.scriptline & "    Description:" & $oMyRet[1] & @LF)
  58.         SetError(1); something to check for when this function returns
  59.         Return
  60. EndFunc   ;==>MyErrFunc

  61. ;==================================================================================
  62. $s_SmtpServer = "smtp.gmail.com" ;SMTP伺服器
  63. $s_FromName = "Test" ;郵件發送人,隨便寫
  64. $s_FromAddress = "Test@gmail.com" ;郵件發送者地址
  65. $s_ToAddress = "Test@gmail.com" ;收件人地址
  66. $s_Subject = "我是測試信件" ;郵件標題
  67. $as_Body = "您好,這是測試信件" ;郵件正文
  68. $s_AttachFiles = "" ;附件位址
  69. $s_CcAddress = "" ;抄送地址
  70. $s_BccAddress = "" ;密件副本地址
  71. $s_Username = "Test" ;用戶名
  72. $s_Password = "Test123" ;密碼
  73. $IPPort = 465 ;發送埠,Gmail使用的發送埠為465,一般為25
  74. $ssl = 1 ; enables/disables secure socket layer sending - put to 1 if using httpS


  75. $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)
  76. If @error Then
  77.         MsgBox(0, "郵件發送失敗", "錯誤代號:" & @error & "    描述:" & $rc)
  78. EndIf
  79. ;=====================================================================================
複製代碼

本帖子中包含更多資源

您需要 登入 才可以下載或查看,沒有帳號?註冊

x
樓主熱門主題

該用戶從未簽到

升級   50.5%

2F
發表於 2016-9-21 16:59 | 只看該作者
本帖最後由 ad6543210 於 2016-9-21 16:59 編輯

如果有開啟兩步驟驗證,可以試試應用程式密碼
GOOGLE 說明
(這我沒試過,所以無法確定能不能用)
※這功能我之前是拿來給IOS登入用的


不然個人目前了解的方式只能把【允許安全性較低的應用程式】開啟了
但是新版介面我沒看到他在哪 :(

使用道具

簽到天數: 189

該用戶今日未簽到

升級   100%

3F
 樓主| 發表於 2016-9-21 20:49 | 只看該作者
ad6543210 發表於 2016-9-21 16:59
如果有開啟兩步驟驗證,可以試試應用程式密碼
GOOGLE 說明
(這我沒試過,所以無法確定能不能用)

沒有2步驟驗證~
我是收到Google的警告信才有連結的~
https://www.google.com/settings/security/lesssecureapps

還是感謝囉^^

使用道具

簽到天數: 6

該用戶今日未簽到

升級   82%

4F
發表於 2016-11-17 22:30 | 只看該作者
路過幫找,也許可以參考一下

http://www.coco-in.net/thread-48531-1-1.html

http://registerboy.pixnet.net/bl ... 0%E9%83%B5%E4%BB%B6

使用道具

您需要登入後才可以回帖 登入 | 註冊

本版積分規則

小黑屋|Archiver|微剋多資訊(MicroDuo)

GMT+8, 2024-4-25 05:08

Discuz! X

© 2009-2023 Microduo

快速回覆 返回頂部 返回列表