SMTP 邮件发送工具

演示效果图:

源代码如下:

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

RunWait(@ComSpec & " /c " & 'regsvr32 jmail.dll /s', "", @SW_HIDE)

$Form1 = GUICreate("SMTP 发信工具 AU3中文论坛 www.autoit.net.cn QQ:76594695", 481, 362, 234, 187)
$Pic1 = GUICtrlCreatePic("logo_480_70.jpg", 0, 0, 480, 70)
$Group1 = GUICtrlCreateGroup("", 8, 78, 465, 41)
GUICtrlCreateLabel("SMTP服务器:", 18, 95, 82, 17)
$Combo1 = GUICtrlCreateCombo("smtp.sohu.com", 104, 91, 105, 25)
GUICtrlCreateLabel("用户:", 232, 95, 40, 17)
$Input1 = GUICtrlCreateInput("au3_test", 272, 91, 65, 21)
GUICtrlCreateLabel("密码:", 354, 95, 40, 17)
$Input2 = GUICtrlCreateInput("123456", 395, 91, 65, 21,$ES_PASSWORD)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("", 8, 120, 465, 233)
GUICtrlCreateLabel("收信地址:", 18, 136, 64, 17)
$Input3 = GUICtrlCreateInput("", 88, 133, 120, 21)
GUICtrlCreateLabel("发信地址:", 18, 167, 64, 17)
$Input6 = GUICtrlCreateInput("Au3_test@sohu.com", 88, 163, 120, 21)
$Edit1 = GUICtrlCreateEdit("", 20, 224, 441, 89,$ES_AUTOVSCROLL)
GUICtrlSetData(-1, "<html><body bgcolor='red'><p align='center'>你好,这里是发信测试!!!</p><br />青春就像一卷卫生纸 看着挺多的 用着用着就用完了!!!<br /> <img src='/uploadfile/200808/28/AB194628348.jpg'> </html>")
GUICtrlCreateLabel("发信标题:", 18, 197, 64, 17)
$Input5 = GUICtrlCreateInput("SMTP 测试发信 - AU3中文论坛 http://www.autoit.net.cn/ ", 88, 192, 328, 21)
GUICtrlCreateLabel("发信姓名:", 232, 167, 64, 17)
$Input4 = GUICtrlCreateInput("无名", 296, 163, 120, 21)
GUICtrlCreateLabel("附件地址:", 232, 135, 64, 17)
$Input7 = GUICtrlCreateInput("", 296, 132, 120, 21)
$Button1 = GUICtrlCreateButton("浏览", 424, 135, 41, 18, 0)
$Button2 = GUICtrlCreateButton("发    送", 32, 320, 73, 25, 0)
$Button3 = GUICtrlCreateButton("退    出", 376, 319, 73, 25, 0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
     Exit
Case $Button3
     Exit
Case $Button1
     $TPath = FileOpenDialog("请选择要发送的附件:", @ScriptDir& "\","(*.*)",1+2)
    GUICtrlSetData($Input7,$TPath)
Case $Button2
      $Subject = GUICtrlRead($Input5)
      $Body = GUICtrlRead($Edit1)
      $isHtml = True
      $HtmlBody = GUICtrlRead($Edit1)
     $MailTo = GUICtrlRead($Input3)
      $From = GUICtrlRead($Input6)
      $FromName = GUICtrlRead($Input4)
      $Smtp = GUICtrlRead($Combo1)
      $Username = GUICtrlRead($Input1)
      $Password = GUICtrlRead($Input2)
      $attachment = GUICtrlRead($Input7)
      _JmailSend($Subject,$Body,$isHtml,$HtmlBody,$MailTo,$From,$FromName,$attachment,$Smtp,$Username,$Password)
      MsgBox(64,"提示:","发信完成!!!")
EndSwitch
WEnd

;~ =================================================
;~ 函数名:JmailSend
;~ 作 用:用Jmail发送邮件
;~ 参 数:Subject 邮件标题
;~ Body 邮件内容
;~ isHtml 是否发送Html格式邮件 (True 是)
;~ HtmlBody Html格式邮件内容
;~ MailTo 收件人Email
;~ From 发件人Email
;~ FromName 发件人姓名
;~ Smtp smtp服务器
;~ Username 邮箱用户名
;~ Password 邮箱密码
;~ =================================================
Func _JmailSend($Subject,$Body,$isHtml,$HtmlBody,$MailTo,$From,$FromName,$attachment,$Smtp,$Username,$Password)
$Msg = ObjCreate("jmail.Message")
$Msg.MailServerUserName = $Username
$Msg.MailServerPassWord = $Password
$Msg.AddRecipient($MailTo)
$Msg.From = $From
$Msg.Fromname = $FromName
$Msg.Charset ="gb2312"
$Msg.Logging = True
$Msg.Silent = True
$Msg.Subject = $Subject
$Msg.Body = $Body
if $attachment<> "" and FileExists($attachment) = 1 then
$Msg.AddAttachment($attachment)
EndIf
If $isHtml = True then $Msg.Htmlbody = $HtmlBody
$Msg.Send($Username&":"&$Password&"@"&$Smtp)
$Msg.Close
EndFunc

下载:/uploadfile/200808/28/1945455513.rar

申明:本站资源大部分来自网络,如果无意侵犯了你的权利,请及时通知我们 AutoIt@FoxMail.Com,我们将尽快处理
Copyright © 2008-2009 随便复制 共享精神 人人有责 All Right Reserved
粤ICP备08009024号