Windows Batch - Getting Error when trying to send mail via blat.exe - windows

I have a simple batch-script, where at the end I want to send an automated e-mail by calling the function blat.exe:
blat.exe -body "Das ist ein Test von Admin" -s "ABCDEFGH" -attacht "\\server\C\applic\abcd\tool\output\datafile.txt" -f mail#adress.com -t mail#adress.com
I am getting the following error:
C:\C\applic\abcd\tool>blat.exe -body "Das ist ein Test von Admin" -s "ABCDEFGH" -attacht "\\server\C\applic\abcd\tool\output\datafile.txt" -f mail#adress.com -t mail#adress.com
-body does not exist
I cannot figure out why it isn't working. Can anyone help here?

Related

Why does my powershell script not wrap my path correctly?

I've been tinkering with a Powershell script to automate some Streamlink stuff, and it's going okay, but I'm having an issue with the way streamlink is passing a command along, specifically with regards to wrapping the file path.
Here is the code (forgive the terrible formatting, I am not a pro, I'm only a beginner.)
Set-Location (Split-Path $MyInvocation.MyCommand.Path)
$scriptdir = Split-Path $MyInvocation.MyCommand.Path
$streamurl = Read-Host -Prompt 'Stream URL'
$channel = youtube-dl --cookies $scriptdir\Resources\cookies.txt --write-description --skip-download -o "%(uploader)s" --get-filename $streamurl
if (-not (Test-Path -LiteralPath $scriptdir\Recordings\$channel\)) {
try {
New-Item -Path $scriptdir\Recordings\$channel\ -ItemType Directory -ErrorAction Stop | Out-Null #-Force
}
catch {
Write-Error -Message "Unable to create directory '$channel'. Error was: $_" -ErrorAction Stop
}
"Successfully created directory '$channel'."
}
streamlink-auth $scriptdir\Resources\cookies.txt --retry-streams 10 -o "$scriptdir\Recordings\$channel\stream.mp4" $streamurl best
$scriptdir = Where the script is running
$streamurl = Self explanatory
$channel = the channel name of the stream
The issue I'm having is that when this command is passed along to streamlink, it seems to be wrapping wrong, as when streamlink tries to run the command, I get the following error:
streamlink args: --retry-streams 10 -o W:\recordings\Recordings\【LIVE】新宿 大ガード交差点 Tokyo Shinjuku Live Ch\stream.mp4 https://www.youtube.com/watch?v=RQA5RcIZlAM best
usage: streamlink [OPTIONS] <URL> [STREAM]
streamlink: error: unrecognized arguments: Shinjuku Live Ch\stream.mp4 https://www.youtube.com/watch?v=RQA5RcIZlAM best
Source:【LIVE】新宿 大ガード交差点 Tokyo Shinjuku Live Ch
I also tested this with a fully english channel (with the same script) and got the following:
streamlink args: --retry-streams 10 -o W:\recordings\Recordings\Watson Amelia Ch. hololive-EN\stream.mp4 https://www.youtube.com/watch?v=EeC6OHBRFTc best
usage: streamlink [OPTIONS] [STREAM]
streamlink: error: unrecognized arguments: hololive-EN\stream.mp4 https://www.youtube.com/watch?v=EeC6OHBRFTc best
Source: Watson Amelia Ch. hololive-EN
It seems that while the directory can be created fine, passing the variables into the streamlink command fails somewhere along the line. This can be worked around by simply moving into the channel directory with:
cd $scriptdir\Recordings\$channel\
and running the command without the extra variables in the path, but that's not the way I'd like to do it. I also want to add that youtube-dl has no issues with writing files to the directories created with this script as my postprocessing script writes files there without trouble, and powershell can still remove files there too.
I have asked the streamlink folks, and it's definitely not on their end, so obviously it's a powershell thing.
How do I solve this problem, because I am genuinely stumped now.
I'm dumb.
Turns out when you pass something into a command, you have to pass it with Double quote, then single quote.
So instead of:
streamlink-auth $scriptdir\Resources\cookies.txt --retry-streams 10 -o "$scriptdir\Recordings\$channel\stream.mp4" $streamurl best
It needs to be:
streamlink-auth $scriptdir\Resources\cookies.txt --retry-streams 10 -o "'$scriptdir\Recordings\$channel\stream.mp4'" $streamurl best
Sorry for being the dum.

Why is the message of the shutdown pop-up cut off?

I am working on a prank Program that randomly reboots your pc while also doing other stuff.
Anyways, I am currently working on the reboot part and I came up with this command:
shutdown -g -t 30 -d p:2:18 -c "Dieser Computer wurde von einer externen Quelle übernommen und wird momentan infiziert mit dem WannaCry Virus. Um nicht-autorisierten Zugriff auf anderen Computern in diesem Netzwerk zu vermeiden starten wir nun Ihr Gerät neu." -f
My Problem is that the text is being cut off because of no particular reason. This is what the pop-up looks like:
The Pop-Up
I did some research on why this could happen, but I see no reason.
/c "comment": This command option allows you to leave a comment describing the reason for the shutdown or restart. You must include quotes around the comment. The maximum length of the comment is 512 characters.
Source: https://www.lifewire.com/shutdown-command-2618100
Does anyone know why this could happen?
Thanks in advance
TRG
Interesting, I can reproduce using an even shorter message like "nicht-auto" or "n-a". Perhaps it interprets "-a" like a new parameter, despite being quoted. If you remove the dash "-", it works. Looks like a bug to me.
A workaround is to replace the dash by an alternative Unicode character:
shutdown -g -t 30 -d p:2:18 -c "nicht$([char]0x2010)autorisierten" -f

Easily catch error from maven install task in build pipeline in Azure Devops?

In Azure Devops when your Maven build task fails it will display an an error like below in the build summary:
Maven build error
Now if you click in and scroll up you will be able to find the error next to the reactor summary. This is easy enough to do at home with a mouse and a big screen but for some of our devs on trains or in cafes it can be quite an effort for them to find the error. I want to be able to make the error easier to find. Some suggestions I've thought of but not sure how to implement are below. Do you have any other good ideas?
Reduce output of maven logs - I've tried the -q flag but it doesn't seem to work for this task?
Use rest api somehow to find the error and then send it to a slack channel with a webhook - Not sure how to find the log or error with the rest api though
So I can help with how you might grab the error out of the build logs and send it over to slack.
Assuming we are going to run this task as the next task after the build error.
We can get the build logs via the API. Make sure to add the system_access token so you can auth.
Once we have all the logs grab the url out of the response to download the last log
Download the last log
Parse it and find the [[error]] lines
Marshal the message to slack \ or do whatever else you want with it
YAML
- pwsh: |
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user, $env:System_AccessToken)))
$uriLogs = "$($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)$env:SYSTEM_TEAMPROJECTID/_apis/build/builds/$env:BUILD_BUILDID/logs?api-version=5.1"
$response = Invoke-RestMethod -Uri $uriLogs -Method 'GET' -Headers #{Authorization = ("Basic {0}" -f $base64AuthInfo)}
$logUrl =$response.value[-1].url
$webContent = Invoke-WebRequest -Uri $logUrl -Method 'GET' -Headers #{Authorization = ("Basic {0}" -f $base64AuthInfo)}
$ErrorMessage = $webContent.Content.tostring() -split "[`r`n]" | select-string "[[Error]]"
Write-Output "Error lines found " $ErrorMessage
$postSlackMessage = #{token=$env:SLACK_TOKEN;channel="#user,#channel-name";text=$ErrorMessage}
Invoke-RestMethod -Uri https://slack.com/api/chat.postMessage -Body $postSlackMessage
env:
system_accesstoken: $(System.AccessToken)
condition: failed()
Other alternatives:
parse the log, find the error, and then send a link to the failure directly at that line number. There is a well known format for direct links to each line.
send a direct link to download just the error part of the log. See startLine and endLine parameters here.
I added a line to top of powershell script to solve the error
Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a receive.
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
If you don't have any problem about tls you don't need to add this line.
Powershell:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$uriLogs = "$($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)$env:SYSTEM_TEAMPROJECTID/_apis/build/builds/$env:BUILD_BUILDID/logs?api-version=5.0"
$response = Invoke-RestMethod -Uri $uriLogs -Method Get -Headers #{ Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"}
$logUrl = $response.value[-1].url
$webContent = Invoke-WebRequest -Uri $logUrl -Method GET -Headers #{ Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"}
$ErrorMessage = $webContent.Content.tostring() -split "[`r`n]" | select-string "[[error]]"
Write-Output "Error lines found " $ErrorMessage

Issues with newline while using blat

I have to send a mail via BLAT. We are shifting from Postie to BLAT. The send mail refuses to send the mail via a batch file.
My code goes as follows
REM ########### Initialize BLAT SMTP Server and User Name #######################
ECHO.
%V_EMAIL_PATH%\blat.exe -install %V_HOST% "mno#xyz.com"
ECHO.
REM ------------------------ Send Email Notifications ---------------
#ECHO ON
set V_EMAIL_ID="abcd#xyz.com"
set V_SUBJ="Test mail to a group"
set V_MSG="Hello|test mail to prevent failure during delivery while sending automated mails|Thanks|mno"
GOTO Sendemail
:Sendemail
%V_EMAIL_PATH%\blat.exe -body %V_MSG% -to "%V_EMAIL_ID%" -from "mno#xyz.com" -subject "Test Mail"
The error being thrown is as follows
D:\pmserver\pm-work\Utilities\blat.exe -body "Hello test mail to prevent failure during delivery while sending automated mails. Thanks RM Primary" -to "abcd#xyz.com" -from "mno#xyz.com" -subject "Test Mail"
Blat v2.2.2 (build : Feb 26 2004 10:37:13)
Blat saw and processed these options, and was confused by the last one...
Hello|test mail to prevent failure during delivery while sending automated mails.|Thanks|mno
Do not understand argument: Hello|test mail to prevent failure during delivery while sending automated mails|Thanks|mno
I tried using breakline as well but even that is failing.
reekar V
try this:
#echo OFF &SETLOCAL
set "V_EMAIL_ID=abcd#xyz.com"
set "V_SUBJ=Test mail to a group"
set "V_MSG=Hello|test mail to prevent failure during delivery while sending automated mails|Thanks|mno"
%V_EMAIL_PATH%\blat -body "%V_MSG%" -to "%V_EMAIL_ID%" -from "mno#xyz.com" -subject "Test Mail"

How can I send an email from the command line using blat when the body contains carriage returns and line feeds?

I have a windows server which sends emails to me through a BASIC program. If the message body contains carriage returns/line feeds then the email never finishes. Only the first line is sent to me. I tried replacing them with \n but that didn't help as the email came to me with the \n in it. Any ideas?
Here is the command I'm using:
blat -to mike.roosa#toltsg.com -subject "[DEV] PO Detail Report" -body "Attached file
is ready for import.
From 01/01/09 to 01/29/09
PO Status not egual to 'C'" -attach "C:\TXT\PODetail_26879.csv" -log
C:\EMAIL.LOG\20090129.TXT -timestamp'.
If you want to do it all inline use the '|' character
-body 1st line|second line|third line
You can put the body in a text file and have blat send that:
blat [text file here] -to mike.roosa#toltsg.com -subject "[DEV] PO Detail Report" -attach "C:\TXT\PODetail_26879.csv" -log
C:\EMAIL.LOG\20090129.TXT -timestamp'
Just use Mail Alert Simple Mailer:
https://sourceforge.net/projects/mail-alert/
MailAlert.exe -r address#example.com -b "#Your_Directory\File_with_Mail_Body.txt"
You can also attach HTML file as an email body (remember to change PlaintextOnly=no in such a case).

Resources