0% found this document useful (0 votes)
2 views8 pages

Sys Email

This document is a script for sending emails using Windows PowerShell, specifically designed to work with SMTP settings for Office 365. It includes configurations for email recipients, subject, body, and attachments, as well as validation and error handling. The script requires PowerShell version 3 or higher and includes instructions for setting up the necessary environment and credentials.

Uploaded by

atulawnish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views8 pages

Sys Email

This document is a script for sending emails using Windows PowerShell, specifically designed to work with SMTP settings for Office 365. It includes configurations for email recipients, subject, body, and attachments, as well as validation and error handling. The script requires PowerShell version 3 or higher and includes instructions for setting up the necessary environment and credentials.

Uploaded by

atulawnish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 8

601,100

602,"Sys.Email"
562,"NULL"
586,
585,
564,
565,"y39o[?:;[S1vCrVWfnvR4=\\`aDGMN5oU^d9cMc\
Xir;`j9_Mm80hbw7ApwK4v034t_QEKT8nWm2jLkr\2AlU]lk;k4=Gj=3=nmVqI=?
R;`zWj_;=e]VHYNdeXlB<SwY=9XRf3vWdCb\V20G`:eidR@^LpbRNc01AlI?
rDWFtkLvFgNX4ieppYJ`1NtrBnQ7L`uc5X_T"
559,1
928,0
593,
594,
595,
597,
598,
596,
800,
801,
566,0
567,","
588,"."
589,
568,""""
570,
571,
569,0
592,0
599,1000
560,5
pRecipients
pSubject
pBody
pAttachment
pDebug
561,5
2
2
2
2
1
590,5
pRecipients,"bwan@cubewise.com"
pSubject,"Daily Sales"
pBody,"Please open attachment for details"
pAttachment,"c:\TM1\Report\DailySales.xlsx"
pDebug,0
637,5
pRecipients,"List of E-mail Recipients (Comma Seperated)"
pSubject,"E-mail Subject Line"
pBody,"E-mail Body"
pAttachment,"List of Attachments (Optional, Comma Seperated)"
pDebug,"Debug Mode: (0 = False, 1 = True)"
577,0
578,0
579,0
580,0
581,0
582,0
603,0
572,47

#****Begin: Generated Statements***


#****End: Generated Statements****

###################################################################################
####
#
# READ ME
# This is a script that uses Windows Powershell sending e-mail
# In order to use the script properly, please make sure the Powershell version is
at least version 3
# For Windows 2008 R2:
# http://social.technet.microsoft.com/wiki/contents/articles/20623.step-by-step-
upgrading-the-powershell-version-4-on-2008-r2.aspx
# Installing_the_DOTnet_amp_after_that_reboot_is_required
# Written by: Cubewise
# Date: 13 Nov 2019
#
###################################################################################
####

cCubeConfig = 'Sys Parameter';

cMailDelim01 = ',';
cMailDelim02 = ';';

cRecipients = pRecipients;
cMailSubject = pSubject;
cMailBody = pBody;
cMailAttachments = pAttachment;

cSMTPServer = 'smtp.office365.com';
cSMTPPort = '587';
cMailSender = 'edu@cubewise.com';
cMailCredentialUserName = 'edu@cubewise.com';
cMailCredentialPassword = 'MyPassword';
cMailSSL = 'Y';

nError = 0;

###################################################################################
####
#
# VALIDATION
#
###################################################################################
####

If (nError <> 0);


ProcessBreak();
Endif;

573,3

#****Begin: Generated Statements***


#****End: Generated Statements****
574,3

#****Begin: Generated Statements***


#****End: Generated Statements****
575,111

#****Begin: Generated Statements***


#****End: Generated Statements****

######################
### Quit Process When Validation Failed
######################
If (nError <> 0);
ProcessQuit();
Endif;

######################
### Update Recipients so that it supports the format that Powershell supports
######################
sMailRecipients = '';
sRecipients = cRecipients;
nDelimIndex = 1;
While (nDelimIndex <> 0 & Long(sRecipients) > 0);
nDelimIndex01 = Scan(cMailDelim01, sRecipients);
nDelimIndex02 = Scan(cMailDelim02, sRecipients);
If (nDelimIndex01 <> 0 & nDelimIndex02 <> 0);
If (nDelimIndex01 < nDelimIndex02);
nDelimIndex = nDelimIndex01;
Else;
nDelimIndex = nDelimIndex02;
Endif;
ElseIf (nDelimIndex01 <> 0 & nDelimIndex02 = 0);
nDelimIndex = nDelimIndex01;
ElseIf (nDelimIndex01 = 0 & nDelimIndex02 <> 0);
nDelimIndex = nDelimIndex02;
ElseIf (nDelimIndex01 = 0 & nDelimIndex02 = 0);
nDelimIndex = 0;
Endif;
sRecipient = '';
If (nDelimIndex <> 0);
sRecipient = Trim(SubSt(sRecipients, 1, nDelimIndex - 1));
sRecipients = Trim(Subst(sRecipients, nDelimIndex + 1, Long(sRecipients) -
Long(sRecipient)));
Else;
sRecipient = Trim(sRecipients);
Endif;
If (sRecipient @<> '');
sMailRecipient = Char(39) | Trim(sRecipient) | Char(39);
If (sMailRecipients @<> '');
sMailRecipients = sMailRecipients | ',';
Endif;
sMailRecipients = sMailRecipients | sMailRecipient;
Endif;
End;

######################
### Update Attachments so that it supports the format that Powershell supports
######################
sMailAttachments = '';
sAttachments = cMailAttachments;
nDelimIndex = 1;
While (nDelimIndex <> 0 & Long(sAttachments) > 0);
nDelimIndex01 = Scan(cMailDelim01, sAttachments);
nDelimIndex02 = Scan(cMailDelim02, sAttachments);
If (nDelimIndex01 <> 0 & nDelimIndex02 <> 0);
If (nDelimIndex01 < nDelimIndex02);
nDelimIndex = nDelimIndex01;
Else;
nDelimIndex = nDelimIndex02;
Endif;
ElseIf (nDelimIndex01 <> 0 & nDelimIndex02 = 0);
nDelimIndex = nDelimIndex01;
ElseIf (nDelimIndex01 = 0 & nDelimIndex02 <> 0);
nDelimIndex = nDelimIndex02;
ElseIf (nDelimIndex01 = 0 & nDelimIndex02 = 0);
nDelimIndex = 0;
Endif;

sAttachment = '';
If (nDelimIndex <> 0);
sAttachment = Trim(SubSt(sAttachments, 1, nDelimIndex - 1));
sAttachments = Trim(Subst(sAttachments, nDelimIndex + 1,
Long(sAttachments) - Long(sAttachment)));
Else;
sAttachment = Trim(sAttachments);
Endif;
If (sAttachment @<> '');
sMailAttachment = Char(39) | Trim(sAttachment) | Char(39);
If (sMailAttachments @<> '');
sMailAttachments = sMailAttachments | ',';
Endif;
sMailAttachments = sMailAttachments | sMailAttachment;
Endif;
End;

######################
### Create Command and Execute
######################
sCommandPS = '$securepass = ConvertTo-SecureString -AsPlainText -String ' |
Char(39) | cMailCredentialPassword | Char(39) | ' -Force;';

sCommandPS = sCommandPS | 'Send-MailMessage';


sCommandPS = sCommandPS | ' -From ' | Char(39) | cMailSender | Char(39) | ' -
Subject ' | Char(39) | cMailSubject | Char(39) | ' -Body ' | Char(39) | cMailBody |
Char(39);
sCommandPS = sCommandPS | ' -To ' | sMailRecipients;
sCommandPS = sCommandPS | ' -SmtpServer ' | Char(39) | cSMTPServer | Char(39);
sCommandPS = sCommandPS | ' -Port ' | cSMTPPort;
sCommandPS = sCommandPS | ' -Credential (New-Object
System.Management.Automation.PSCredential(' | Char(39) | cMailCredentialUserName |
Char(39) | ',$securepass))';
sCommandPS = sCommandPS | If (sMailAttachments @<> '', ' -Attachments ' |
sMailAttachments, '');
sCommandPS = sCommandPS | If (cMailSSL @= 'Y', ' -UseSsl', '');
sCommandPS = sCommandPS | ' -DeliveryNotificationOption never';

#asciioutput('Powershell Email Command.txt', sCommandPS);


sCommandPS = 'powershell ' | sCommandPS;

If (pDebug = 0);
ExecuteCommand(sCommandPS, 1);
Endif;

576,CubeAction=1511
DataAction=1503
CubeLogChanges=0
930,0
638,1
804,0
1217,0
900,
901,
902,
938,0
937,
936,
935,
934,
932,0
933,0
903,
906,
929,
907,
908,
904,0
905,0
909,0
911,
912,
913,
914,
915,
916,
917,0
918,1
919,0
920,50000
921,""
922,""
923,0
924,""
925,""
926,""
927,""

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy