Mail sender address is not getting updated in Debian - email

I'm trying to send email, but I constantly get wrong sender email address.
From address supposed to be "xyz#company.com" but it is coming as "xyz#guid"
OS details:
The command tried so far:
echo "Hello there" | mail -s "Test Mail" -r sender#company.com mail-to#receiver#company.com
echo "Hello there" | mail -s "Test Mail" -r mail-from#sender#company.com mail-to#receiver#company.com
echo "Hello there" | mail -s "Test Mail" -r 'First Last sender#company.com' receiver#company.com
echo "Hello there" | mail -s "Test Mail" -aFrom:'First Last sender#company.com' receiver#company.com
echo "Hello there" | mail -s "Test Mail" receiver#company.com -aFrom:sender#company.com
echo "Hello there" | mail -s "Test Mail" -aFrom:IROL-Admin<sender#company.com> receiver#company.com

I got it working with the below SSMTP.Conf
root=sender#company.com
mailhub=mailhost.company.com:25
FromLineOverride=YES

Related

Concatenating variables to pass to exe in powershell

I'm writing a powershell script which calls an exe using the input parameters. This is my code:
param([string]$sourceIP, [string]$destinationIP, [string]$prefix)
$ErrorActionPreference = "Stop"
try
{
Write-Host "Starting Copy of Keyspaces to Dev"
Write-Host "Copying One"
.\CopyDatabase.exe -s $sourceIP -o $($prefix)_one -d $destinationIP -n $($prefix)_one -c
Start-Sleep -s 2
Write-Host "Copying Two"
.\CopyDatabase.exe -s $sourceIP -o $($prefix)_two -d $destinationIP -n $($prefix)_two -c
Start-Sleep -s 2
Write-Host "Copying Three"
.\CopyDatabase.exe -s $sourceIP -o $($prefix)_three -d $destinationIP -n $($prefix)_three -c
Start-Sleep -s 2
Write-Host "Copying Four"
.\CopyDatabase.exe -s $sourceIP -o $($prefix)_four -d $destinationIP -n $($prefix)_four -c
Write-Host "Finished Backup"
}
catch
{
write-host "EXCEPTION:"
write-host "Exception Type: $($_.Exception.GetType().FullName)"
write-host "Exception Message: $($_.Exception.Message)"
exit -1
}
It's working as I expect, except that $($prefix)_keyspace gives me prefix _keyspace where I want prefix_keyspace. I'm sure I can write a function or make a new variable for each concatenation, but I'm wondering if there's a command I can use for this that'll save me from having to do that. Thanks!
Replace the try block with this:
try
{
Write-Host "Starting Copy of Keyspaces to Dev"
Write-Host "Copying One"
.\CopyDatabase.exe -s $sourceIP -o ${prefix}_one -d $destinationIP -n ${prefix}_one -c
Start-Sleep -s 2
Write-Host "Copying Two"
.\CopyDatabase.exe -s $sourceIP -o ${prefix}_two -d $destinationIP -n ${prefix}_two -c
Start-Sleep -s 2
Write-Host "Copying Three"
.\CopyDatabase.exe -s $sourceIP -o ${prefix}_three -d $destinationIP -n ${prefix}_three -c
Start-Sleep -s 2
Write-Host "Copying Four"
.\CopyDatabase.exe -s $sourceIP -o ${prefix}_four -d $destinationIP -n ${prefix}_four -c
Write-Host "Finished Backup"
}
This should do your work. Not tested.

How to send Email from a Batch file?

I want the Email and Message in the Code to be sent to my Email "example#gmail.com'. I'm new to coding. Please help me to do this.
#echo off
color a
title Message Me
echo Instructions:
echo 1) Type the message and hit ENTER/RETURN
cd "C:\MessageMe"
set /p user=Email ID:
set /p message=Message:
echo Username="%user%" Message="%message%">Sent_Items.txt
echo Press any key to continue
pause >n
echo Loading.....
echo Enter E-Mail Again
set /p user=Email ID:
echo Username="%user%">Confirmed.txt
echo.
echo Press any key to Send
echo.
echo.
pause >
echo.
echo Processing...
echo.
echo.
echo.
echo.
echo.
pause >n
To send Emails from the Windows command-line, you can
...forget using raw telnet.exe as it cannot accept input from a file
...use a telnet.exe replacement like Albert Yale's telnet scripting tool
...use an actual command-line Email client like blat
...use PowerShell, like e.g. this1:
$EmailFrom = “yourgmailadress#gmail.com”
$EmailTo = “destination#somedomain.com”
$Subject = “The subject of your email”
$Body = “What do you want your email to say”
$SMTPServer = “smtp.gmail.com”
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“usr”, “pass”);
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

Powershell plink telnet command output into var

I'm trying to write a script (based on some internet examples) for some telnet/ssh command execution, using powershell and plink. But the main feature, which I'd like to implement - is to catch this command's output into the variable or a text file. How can I intercept the output of the specific command?
For example: when I send "get-status" command, it returns "Status is 01 02 03". Can I assign this string to the var or text file? Maybe, only "01 02 03" without "Status" text?
$ps = New-Object -TypeName System.Diagnostics.Process
$ps.StartInfo.UseShellExecute = $false
$ps.StartInfo.RedirectStandardInput = $true
$ps.StartInfo.FileName = "plink"
$ps.StartInfo.Arguments = "-telnet XXX.XXX.XXX.XXX"
[void]$ps.Start()
$PlinkStreamWriter = $ps.StandardInput
Start-Sleep -m 500
$PlinkStreamWriter.Write("login`r")
Start-Sleep -m 500
$PlinkStreamWriter.Write("password`r")
Start-Sleep -m 500
$PlinkStreamWriter.Write("get-status")
Start-Sleep -m 500
Write-Host "Status string: " .....
$PlinkStreamWriter.Write("exit`r")
$PlinkStreamWriter.Close();
if (!$ps.HasExited) { $ps.Kill() }
If I understand you correctly, when you send
$PlinkStreamWriter.Write("get-status")
You receive
Status is 01 02 03
If this is consistent and you want to assign this value to a variable, just define the variable at the beginning of your command:
$result = $PlinkStreamWriter.Write("get-status")
Now if you want to remove "Status is" from the value stored in $result:
$result = $result -replace "Status is ",""
Now $result contains only "01 02 03"
You can now update your write-host command:
Write-Host "Status string: $result"
A simple redirect (>) is all that is needed. I verified this works for me in PowerShell v5.1.22000.282. Here is my approach for anyone who needs it.
$filepath = "$PSScriptRoot"
$PUTTY="$Env:ProgramFiles\PuTTY\plink.exe"
$commands = #"
y
vncserver -geometry 1920x1080
exit"#
#echoes yes onto putty prompt if it exists and spits output to out.txt
echo $commands | & $PUTTY -ssh $IP -l $USER -pw $PW > "$filepath/out.txt"
This may be of use, you can redirect the outputs from error messages and warning messages into standard out. Example:
Invoke-Expression "cmd /c 'C:\Program Files (x86)\PuTTY\plink.exe'$plinkcmd 4>&1 3>&1 2>&1"

Pass powershell variable to batch script

Here is powershell script
$a = get-date -format "MMM-d-yyyy"
Start-Process "D:\Script\send_report.bat"
send_report.bat uses blat to send email
D:
cd "D:\Program Files (x86)\blat321\full"
blat -s "Daily Report" -i "Our Team" -to member1#team.org,member2#team.org -body "Please see attached." -priority 1 -attach D:\Script\Daily_Report.xlsx
How do I insert $a into send_report.bat? I would like value of $a next to "Daily Report"
#echo off
cd /d "D:\Program Files (x86)\blat321\full"
set "the_date=%~1"
blat -s "Daily Report" -i "Our Team" -to member1#team.org,member2#team.org -body "Please see attached." -priority 1 -attach D:\Script\Daily_Report_%the_date%.xlsx
and call the bat like :
$a = get-date -format "MMM-d-yyyy"
Start-Process "D:\Script\send_report.bat" $a
In your PowerShell script, add $a as a parameter to the batch file:
Start-Process "D:\Script\send_report.bat" $a
In you batch file reference the parameter as %1.
blat -s "Daily Report %1" -i "Our Team" -to member1#team.org,member2#team.org -body "Please see attached." -priority 1 -attach D:\Script\Daily_Report.xlsx

Powershell Script To Reindex WSUS DB and email results

Hi I am trying to write a PowerShell script that reindexs the WSUS Database and I am stuck. So far I have a separate config file that holds the email details of the server, and I think I have got the WSUS reindex working. However I'm stuck getting the data from the sql query. I have used a TechNet article as a starting point.
The code I have so far is:
$configKey = #{}
Get-Content server.ini | ForEach-Object {
$keys = $_ -split "="
$configKey += #{$keys[0]=$keys[1]}
}
cd "c:\Program Files\Microsoft SQL Server\100\Tools\Binn\"
"Invoke-sqlcmd -I -i"c:\scripts\WSUSDBMaintenance.sql" -S "np:\\.\pipe\MSSQL$MICROSOFT##SSEE\sql\query"
#file backup
$body += '<font size="5" face="Calibri"Windows Server Reindex Report:</font><br / ><font face="Calibri">'
$body += $Result + "<br>"
"
Invoke-Sqlcmd -Query "PRINT 'Number of indexes to rebuild: ' + cast(##ROWCOUNT as nvarchar(20)';" -Verbose
$body += "</div></font>"
$subject += $configKey.company
#Send Email
Send-MailMessage -From $configKey.from -To $configKey.to -Subject $subject -Body $Body -BodyAsHtml -Smtpserver $configKey.server
a few things jump out at me.
"Invoke-sqlcmd -I -i"c:\scripts\WSUSDBMaintenance.sql" -S "np:\.\pipe\MSSQL$MICROSOFT##SSEE\sql\query"
should probably be
Invoke-sqlcmd -I -i "c:\scripts\WSUSDBMaintenance.sql" -S "np:\.\pipe\MSSQL$MICROSOFT##SSEE\sql\query"
And you have an extraneous double quote here:
$body += $Result + "<br>"
"<<<<<<<<<<<<<<<<<<<<<<<<<
Also, are the tools really in a directory called Binn rather than Bin?