Jump to content

Send mail with attachment


Recommended Posts

Hello,

read on forum several send mail example. Few about send mail + attachment

I want to include this feature in one of my script, but not find an UDF or simple example. (some required external resource [gmail, etc])

Post here a vbs script that done this task in simple way :

'_________________________________________________________________
'      set vars
'_________________________________________________________________
dim Attachment
set vArgs = WScript.Arguments
Attachment = "c:\tmuninst.ini"
Set objFSO = CreateObject("Scripting.FileSystemObject")


'_________________________________________________________________
'       set MAIL
'_________________________________________________________________
Set objMessage = CreateObject("CDO.Message") 
objMessage.Subject = "this is Subject  " & date & " " & TIME
objMessage.From = "mike@autoit.it" 
objMessage.To = "robert@autoit.it" 
objMessage.TextBody = "send report"


'_________________________________________________________________
'   In attachment exist send 
'_________________________________________________________________
If objFSO.FileExists(Attachment) Then
    objMessage.AddAttachment Attachment
Else
    objMessage.Subject = date & " " & TIME & ". Report NOt exists. "
End If


'_________________________________________________________________
'       SERVER SMTP
'_________________________________________________________________

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 

'NOME O IP SERVER CON SMTP ATTIVO
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "yyy.xxx.1.36"

'PORTA DEL SERVER (SMTP ASCOLTA SULLA 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 

objMessage.Configuration.Fields.Update


'_________________________________________________________________
'       SEND
'_________________________________________________________________
objMessage.Send

I've an SMTP mail server on my lan so i want to use it (not want to use external resource [gmail, yahoo, etc])

Anyone can suggest me something easy to include this in a script ?

Thank you for reading,

m.

Link to comment
Share on other sites

Do you have outlook (but not exkspress)?

$oOApp = ObjCreate("Outlook.Application")

$oOMail = $oOApp.CreateItem($olMailItem)

$oOMail.Save

With $oOMail

.To = (" type@here.com")

.Subject = "test mail"

.BodyFormat = 3

.Importance = 1

.Body = "Hi there"

.attachments.add ("full file path")

.Display

.Send

EndWith

Link to comment
Share on other sites

thank you for reply,

but understand that UDF needs external SMTP server with username password. (eg Gmail)

my script must run in work intranet with no internet access, but internal mail server (that support send trought SMTP)

You know if is possible use also LAN resources ?

m.

Link to comment
Share on other sites

Or you could use an external program like blat (Blat is a Win32 command line utility that sends eMail using SMTP).

No need for installation (but you can), all necessary information can be provided on the command line.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

thank you for reply,

but understand that UDF needs external SMTP server with username password. (eg Gmail)

my script must run in work intranet with no internet access, but internal mail server (that support send trought SMTP)

You know if is possible use also LAN resources ?

m.

I think this UDF will work in this scenario. Just try it...

Maybe there must be set some parametres for connection.

Link to comment
Share on other sites

I've implemented a simliar script on a couple servers where I work and if you have a mail server just use that as the smtp server and youll be able to send internal emails only, and if you want to send external emails then youll have to use username / password.

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Link to comment
Share on other sites

Hi,

i'm using _INetSmtpMail function with an internal LotusNotes SMTP Server.

You don't need user and password verifaction, if your smtp sever is configured to use it without user verification.

In our case, the LoNo SMTP does only IP Filtering on SMTP Port.

Depending on your SMTP server you may define $s_helo = "" and $s_first = -1 (see help file _INetSmtpMail function)

Good luck

;-))

Stefan

Edited by 99ojo
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...