找回密码
 加入
搜索
查看: 5711|回复: 10

Autoit怎样编写可以带附件发送功能的邮件脚本

  [复制链接]
发表于 2009-5-17 00:27:34 | 显示全部楼层 |阅读模式
本帖最后由 autosonix 于 2009-5-19 13:50 编辑

麻烦高手给代码,供研究,谢谢了!谢谢!
发表于 2009-10-13 17:15:19 | 显示全部楼层
找不到啊!!
发表于 2011-6-10 12:27:29 | 显示全部楼层
我也在测试,还没有搞定
发表于 2011-8-14 14:55:42 | 显示全部楼层
我也想知道
发表于 2011-10-10 16:09:02 | 显示全部楼层
代码在此   但愿LZ在两年后依然用得到
#include <file.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$Button1 = GUICtrlCreateButton("发邮件", 16, 16, 585, 401)
GUICtrlSetFont(-1, 80, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        sendmail()

        EndSwitch
WEnd
;发送邮件====================================================================
Func sendmail()
$s_SmtpServer = "smtp.163.com" ;SMTP服务器
$s_FromName = "gvg110119" ;邮件发送人
$s_FromAddress = "" ;邮件发送者地址
$s_ToAddress = "" ;收件人地址
$s_Subject = "邮件测试" ;邮件标题
$as_Body = "邮件测试啊啊啊啊啊!!!" ;邮件正文
$s_AttachFiles = "" ;附件地址
$s_CcAddress = "" ;抄送地址
$s_BccAddress = "" ;密件抄送地址
$s_Username = "" ;用户名
$s_Password = "" ;密码
$IPPort = 25 ;发送端口,Gmail使用的发送端口为465
$ssl = 0
$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   ;==>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
;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()
$HexNumber = Hex($oMyError.number, 8)
$oMyRet[0] = $HexNumber
$oMyRet[1] = StringStripWS($oMyError.description, 3)
ConsoleWrite("### COM Error !    Number: " & $HexNumber & "    ScriptLine: " & $oMyError.scriptline & "    Description:" & $oMyRet[1] & @LF)
SetError(1); something to check for when this function returns
Return
EndFunc   ;==>MyErrFunc
;发送邮件结束====================================================================
发表于 2012-10-26 09:17:51 | 显示全部楼层
下载来学习学习 下
发表于 2013-1-10 22:24:54 | 显示全部楼层
回复 6# jj119120


    发邮件.au3 - 1 错误, 2 警告
Error.description, 3)
ConsoleWrite("!>22:23:34 AU3Check 完成. 按下 F4 跳转到下一次错误.[CODE]:2
+>22:23:34 ACNWrapper 完成..
>退出代码: 0        运行时间: 0.485 秒
发表于 2014-9-1 16:44:54 | 显示全部楼层
抄送和附件的参数是如何定义编写的
发表于 2014-9-5 13:53:49 | 显示全部楼层
用Jmail控件
发表于 2014-9-5 14:02:23 | 显示全部楼层
用Jmail控件
发表于 2016-9-12 18:51:39 | 显示全部楼层
学习,学习
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-28 23:24 , Processed in 0.085728 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表