Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '=============Отправка почтового сообщения с вложением============================
- Dim objEmail, MailFrom, MailTo, MailBCC, MailSubject, MailBody, MailAttachment, objArgs, objNamedArgs, re, rv, ss, match, retstr, i
- Set objArgs = WScript.Arguments ' Создаем объект "Аргументы командной строки"
- Set objNamedArgs = objArgs.Named ' Создаем объект "Именованные Аргументы"
- If ((NOT objNamedArgs.Exists("F")) OR ( NOT objNamedArgs.Exists("T"))) Then
- WScript.Echo "No have rigth argument on the command line." & VBCRLF & _
- "This tool Send E-mail for you recepients"& VBCRLF& _
- "Usage: SendMail.vbs </keys:parameters> "& VBCRLF & _
- "KEYS:" & VBCRLF & _
- ""& VBCRLF& _
- "NECESSARY KEYS"& VBCRLF& _
- ""& VBCRLF& _
- "/F:<e-mail> e-mail adress in field FROM"& VBCRLF& _
- "/T:<e-mail> e-mail adress in field TO (May be many adress semicolon separated)"& VBCRLF& _
- ""& VBCRLF& _
- "OPTIONAL KEYS"& VBCRLF& _
- ""& VBCRLF& _
- "/C:<e-mail> e-mail adress in field BCC (BLIND CURRENT COPY)"& VBCRLF& _
- "/S:<text> Text in field SUBJECT"& VBCRLF& _
- "/B:<text> Text in BODY letter"& VBCRLF& _
- "/A:<Drive\path> Link to file which will in ATTACHMENT"& VBCRLF& _
- ""& VBCRLF& _
- "Example: " & VbCrLf & "SendMail.vbs /F:user@host.com /T:user2@host.com /S:""Test Subject"" /B:""Hey guys! This is my letters!"" /A:C:\test.txt"
- WScript.Quit
- End If
- If objNamedArgs.Exists("F") Then
- MailFrom = objNamedArgs("F")
- End If
- If objNamedArgs.Exists("T") Then
- MailTo = objNamedArgs("T")
- End If
- If objNamedArgs.Exists("C") Then
- MailBCC = objNamedArgs("C")
- End If
- If objNamedArgs.Exists("S") Then
- MailSubject = objNamedArgs("S")
- End If
- If objNamedArgs.Exists("B") Then
- MailBody = objNamedArgs("B")
- End If
- If objNamedArgs.Exists("A") Then
- MailAttachment = objNamedArgs("A")
- End If
- ' FUNCTION ============
- Function GetString(sString)
- ' Get one string from nulti-string
- '
- Dim TempString
- GetPrefixNameGroup = sString
- if( InStr(sString, "_") >= 1 ) then
- TempString = Left(sString, InStr(sString, "_")-1)
- GetString = TempString
- end If
- End Function
- '////////////////////////////////////////////////////////////////////////////
- ' FUNCTION ============
- Function TrimString(sString)
- ' Trim prefix of name group
- '
- Dim TempString
- if( InStr(sString, "_") > 1 ) then
- TempString = Mid(sString, InStr(sString, "_")+1)
- TrimString = TempString
- end If
- End Function
- '////////////////////////////////////////////////////////////////////////////
- tempStr = GetString ( MailBody)
- EndLine = Tempstr & VbCrLf
- tempStr = TrimString( MailBody)
- PArt1 = GetString(tempStr)
- EndLine = Endline & Part1 & VbCrLf
- tempStr = TrimString(tempStr)
- Part2 = GetString(tempStr)
- EndLine = Endline & part2 & VbCrLf
- tempStr = TrimString(tempStr)
- part3 = GetString(tempStr)
- EndLine = Endline & part3 & VbCrLf
- tempStr = TrimString(tempStr)
- part4 = GetString(tempStr)
- EndLine = Endline & part4 & VbCrLf
- tempStr = TrimString(tempStr)
- part5 = GetString(tempStr)
- EndLine = Endline & part5 & VbCrLf
- Set objEmail = CreateObject("CDO.Message")
- objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
- '(значение 1 - Send the message using Pickup, например при использовании локального почтового сервера).
- '(значение 2 - Send the message using the network, отсылка через сетевое подключение).
- '(значение 3 - Send the message using the Microsoft Exchange mail submission Uniform Resource Identifier (URI)).
- 'Почтовый сервер
- objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.yandex.ru"
- 'Настройка режима аутентификации
- objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
- 'Значение 1 - означает, что используется базовая аутентификация (Use the basic (clear text) authentication mechanism.).
- 'Значение 0 - без аутентификации (анонимно) (Perform no authentication.).
- 'Значение 2 – аутентификация NTLM (Use the NTLM authentication mechanism.).
- objEmail.Configuration.Fields.Update
- 'Имя пользователя и пароль
- objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "user@host.com"
- objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
- 'Иногда необходимо также определить использование специфического порта (отличного от 25), и время тайм-аута:
- 'objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
- 'objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 20
- 'Задаем будет или нет использоваться SSL
- 'objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
- 'После изменений, вносимых в конфигурацию, изменения надо сохранить:
- objEmail.Configuration.Fields.Update
- objEmail.From = MailFrom
- objEmail.To = MailTo
- objEmail.BCC = MailBCC
- objEmail.Subject = MailSubject
- objEmail.TextBody = Endline
- objEmail.Send
- WScript.Quit(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement