Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.


lchiu7

5356 posts

Uber Geek

Trusted

#260051 8-Nov-2019 10:44
Send private message

I spend some time helping a friend with a small office setup. a number of bat files run every night that back up their important to a NAS and the NAS is synchronised to OneDrive It would be good if at the completion of the execution of those bat files an email could be sent to me so I can look at the output from the backups.

Trying to find an easy way for a bat file to send an email. They are a Gmail user and I have not been able to find an easy way to access Google's SMTP server. But their internet connection is provided by spark so I thought to be able to access the spark SMTP server shouldn't I.?

In a previous site I was able to use a little freeware tool called blat and access the exchange server on the internal Network but this little operation doesn't have its own SMTP server.

Any ideas appreciated.

Thanks




Staying in Wellington. Check out my AirBnB in the Wellington CBD.  https://www.airbnb.co.nz/rooms/32019730  Mention GZ to get a 10% discount

 

System One: Popcorn Hour A200,  PS3 SuperSlim, NPVR and Plex Server running on Gigabyte Brix (Windows 10 Pro), Sony BDP-S390 BD player, Pioneer AVR, Raspberry Pi running Kodi and Plex, Panasonic 60" 3D plasma, Google Chromecast

System Two: Popcorn Hour A200 ,  Oppo BDP-80 BluRay Player with hardware mode to be region free, Vivitek HD1080P 1080P DLP projector with 100" screen, Denon AVRS730H 7.2 Channel Dolby Atmos/DTS-X AV Receiver, Samsung 4K player, Google Chromecast, Odroid C2 running Kodi and Plex

 

 


Filter this topic showing only the reply marked as answer View this topic in a long page with up to 500 replies per page Create new topic
 1 | 2
Dynamic
2890 posts

Uber Geek

Trusted
Lifetime subscriber

  #2350091 8-Nov-2019 10:49
Send private message

Spark often block outgoing Port 25...  can you test with Telnet or similar?

 

telnet smtpservername 25

 

For example if I telnet to smtp.gmail.com, I get a response of 220 smtp.gmail.com ESMTP r24sm3965098pgu.36 - gsmtp

 

I've used and like blat.  There are alternatives as well.





"4 wheels move the body.  2 wheels move the soul."

“Don't believe anything you read on the net. Except this. Well, including this, I suppose.” Douglas Adams

SirHumphreyAppleby
1412 posts

Uber Geek


  #2350093 8-Nov-2019 10:53
Send private message

I maintain CMail so naturally I would recommend that as an alternative to Blat. Blat unfortunately does not support SSL, which is required for sending via Google and many other services. You can use Blat with a third party SSL tool, but you're limited to sending via SMTPS, which is considered deprecated.

 

To use GMail servers, you will need to authenticate, which usually involves allowing less secure applications in your Google account (don't worry, these are still secure), or application passwords. You should also be sending via the message submission port, 587.

 

Note, if you setup your own server, you need to setup SPF, DKIM and ensure your ISP isn't blocking port 25. It's a lot more work than is necessary just to send mail form a batch file.

 

You can also use PowerShell to send messages without any third party software installed.


 
 
 
 


elpenguino
1479 posts

Uber Geek

Subscriber

  #2350095 8-Nov-2019 10:57
Send private message

If you've got Office on the machine you should be able to script it up to send an email easily enough. I do a similar thing from Access.


MurrayM
1995 posts

Uber Geek


  #2350096 8-Nov-2019 10:57
Send private message

I was going to suggest using Blat. I used it many years ago and found it worked fine.


Spyware
2596 posts

Uber Geek

Lifetime subscriber

  #2350100 8-Nov-2019 11:03
Send private message

Run Postfix on an RPi to relay to Spark.





Spark FibreMAX using Mikrotik CCR1009-8G-1S-1S+. UAP, UAP AC Pro, UAP AC Pro Mesh, Apple TV 4, Apple TV 4K, iPad Air 1, iPhone XR, VodaTV Gen 2. If it doesn't move then it's data cabled.


tchart
1697 posts

Uber Geek

Trusted
Subscriber

  #2350103 8-Nov-2019 11:07
Send private message

I usually just use Gmails SMTP servers. You do need to configure the account to use it though.

 

I use the following code in PowerShell to send an email via Gmail;

 

function Send-ToEmail([string]$email, [string]$subject, [string]$body)
{
    try
    {
        $message = new-object Net.Mail.MailMessage
        $message.From = "XYZ@gmail.com"
        $message.ReplyTo = "XYZ@gmail.com"
        $message.To.Add($email)
        $message.Subject = $subject
        $message.Body = $body

 

        $smtp = new-object Net.Mail.SmtpClient("smtp.gmail.com", "587")
        $smtp.EnableSSL = $true;
        $smtp.Credentials = New-Object System.Net.NetworkCredential("XYZ@gmail.com", "PASSWORDGOESHERE");

 

        $smtp.send($message)

 

        $result = $true
    }
    catch
    {
        $result = $false
    }

 

    return $result
 }

 

 


SirHumphreyAppleby
1412 posts

Uber Geek


  #2350106 8-Nov-2019 11:11
Send private message

Spyware:

 

Run Postfix on an RPi to relay to Spark.

 

 

There is no real benefit running an SMTP server delivering to a smart host over having the client deliver to the smart host directly. The biggest drawback with running a server is if mail delivery fails, you may not know about it for a long time. If your batch file handles this directly, it can take appropriate action when failures occur.


 
 
 
 


davidcole
4976 posts

Uber Geek

Trusted

  #2350115 8-Nov-2019 12:06
Send private message

Yeah I had a powershell that would send via gmail.  But with a local smtp server you can do it without requiring smtp authentication.

 

 





Previously known as psycik

OpenHAB: Gigabyte AMD A8 BrixOpenHAB with Aeotech ZWave Controller, Raspberry PI, Wemos D1 Mini, Zwave, Xiaomi Humidity and Temperature sensors and Bluetooth LE Sensors
Media:Chromecast v2, ATV4, Roku3, HDHomeRun Dual
Windows 10
Host (Plex Server/Crashplan): 2x2TB, 2x3TB, 1x4TB using DriveBender, Samsung 850 evo 512 GB SSD, Hyper-V Server with 1xW10, 1xW2k8, 2xUbuntu 16.04 LTS, Crashplan, NextPVR channel for Plex,NextPVR Metadata Agent and Scanner for Plex


fearandloathing
259 posts

Ultimate Geek

Lifetime subscriber

  #2350132 8-Nov-2019 12:54
Send private message

Send-MailMessage is native to PowerShell

 

 

 

$mycredentials = Get-Credential
#$MailServer="your-domain-co-nz.mail.protection.outlook.com"
$MailServer="smtp.office365.com"
#From Address, does not need to be actual mailbox
$Sender="hello.there@your-domain.co.nz"
#Recipients
#$Recipient=@("hello.there@your-domain.co.nz")
$Recipient=@("hello.there@your-domain.co.nz","hello.there2@your-domain.co.nz")

 

Send-MailMessage -From $Sender -To $Recipient -Subject "Testing sending attachment 21" `
    -SmtpServer $MailServer -Body "this message should include an attachment" -Credential $mycredentials -UseSsl

 

    <#
    -Attachments .\test.txt
    -Priority High
    #>


lchiu7

5356 posts

Uber Geek

Trusted

  #2350226 8-Nov-2019 13:56
Send private message

Thanks all. Powershell looks like the way to go. But I'm not experienced in Powershell. The function that tchart documents looks good but I'm entirely sure how to call it. So I create the script as a standalone script that I can call say from a bat file ? The bat file would be doing all my copying etc.




Staying in Wellington. Check out my AirBnB in the Wellington CBD.  https://www.airbnb.co.nz/rooms/32019730  Mention GZ to get a 10% discount

 

System One: Popcorn Hour A200,  PS3 SuperSlim, NPVR and Plex Server running on Gigabyte Brix (Windows 10 Pro), Sony BDP-S390 BD player, Pioneer AVR, Raspberry Pi running Kodi and Plex, Panasonic 60" 3D plasma, Google Chromecast

System Two: Popcorn Hour A200 ,  Oppo BDP-80 BluRay Player with hardware mode to be region free, Vivitek HD1080P 1080P DLP projector with 100" screen, Denon AVRS730H 7.2 Channel Dolby Atmos/DTS-X AV Receiver, Samsung 4K player, Google Chromecast, Odroid C2 running Kodi and Plex

 

 


lchiu7

5356 posts

Uber Geek

Trusted

  #2350452 8-Nov-2019 20:21
Send private message

tchart:

 

I usually just use Gmails SMTP servers. You do need to configure the account to use it though.

 

I use the following code in PowerShell to send an email via Gmail;

 

function Send-ToEmail([string]$email, [string]$subject, [string]$body)
{
    try
    {
        $message = new-object Net.Mail.MailMessage
        $message.From = "XYZ@gmail.com"
        $message.ReplyTo = "XYZ@gmail.com"
        $message.To.Add($email)
        $message.Subject = $subject
        $message.Body = $body

 

        $smtp = new-object Net.Mail.SmtpClient("smtp.gmail.com", "587")
        $smtp.EnableSSL = $true;
        $smtp.Credentials = New-Object System.Net.NetworkCredential("XYZ@gmail.com", "PASSWORDGOESHERE");

 

        $smtp.send($message)

 

        $result = $true
    }
    catch
    {
        $result = $false
    }

 

    return $result
 }

 

 

 

 

 

 

OK this one looked like a great example. I replaced all the fields with my own, the SMTP server not Gmail but my own domain's one on port 465. The SMTP server requires authentication and I am sure I put in the right email address and password (checked it several times)

 

But whenever I run the script it always returns false and no mail is sent.

 

I just invoked the script in the Powershell script by having

 

Send-ToEmail("send to address", "subject line", "some random text in the body")

 

 

 

Not entirely sure what to do now or how to even debug this.





Staying in Wellington. Check out my AirBnB in the Wellington CBD.  https://www.airbnb.co.nz/rooms/32019730  Mention GZ to get a 10% discount

 

System One: Popcorn Hour A200,  PS3 SuperSlim, NPVR and Plex Server running on Gigabyte Brix (Windows 10 Pro), Sony BDP-S390 BD player, Pioneer AVR, Raspberry Pi running Kodi and Plex, Panasonic 60" 3D plasma, Google Chromecast

System Two: Popcorn Hour A200 ,  Oppo BDP-80 BluRay Player with hardware mode to be region free, Vivitek HD1080P 1080P DLP projector with 100" screen, Denon AVRS730H 7.2 Channel Dolby Atmos/DTS-X AV Receiver, Samsung 4K player, Google Chromecast, Odroid C2 running Kodi and Plex

 

 


davidcole
4976 posts

Uber Geek

Trusted

  #2350497 8-Nov-2019 22:39
Send private message

Take out the try and catch lines while you’re figuring it out.  As it’s getting an error somewhere, but the try catch is hiding it from you.





Previously known as psycik

OpenHAB: Gigabyte AMD A8 BrixOpenHAB with Aeotech ZWave Controller, Raspberry PI, Wemos D1 Mini, Zwave, Xiaomi Humidity and Temperature sensors and Bluetooth LE Sensors
Media:Chromecast v2, ATV4, Roku3, HDHomeRun Dual
Windows 10
Host (Plex Server/Crashplan): 2x2TB, 2x3TB, 1x4TB using DriveBender, Samsung 850 evo 512 GB SSD, Hyper-V Server with 1xW10, 1xW2k8, 2xUbuntu 16.04 LTS, Crashplan, NextPVR channel for Plex,NextPVR Metadata Agent and Scanner for Plex


lchiu7

5356 posts

Uber Geek

Trusted

  #2350506 8-Nov-2019 23:52
Send private message

Well persistence and I made progress. Found a script like that I was able to use

 

$EmailFrom = "xxxx@outlook.com"

 

$EmailTo = "yyyy@gmail.com"

 

$Subject = "Test from O365 SMTP "

 

$Body = "Test from O365 SMTP Authentication"

 

$SMTPServer = "smtp.office365.com"

 

$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)

 

$SMTPClient.EnableSsl = $true

 

$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("user@outlook.com", "password");

 

$SMTPClient.Send($EmailTo, $EmailFrom, $Subject, $Subject)

 

 

 

That seemed to work but for the machine I was using I had to alter the Powershell execution policies.

 

Next step is to try to work out how to attach files.  

 

 

 

 





Staying in Wellington. Check out my AirBnB in the Wellington CBD.  https://www.airbnb.co.nz/rooms/32019730  Mention GZ to get a 10% discount

 

System One: Popcorn Hour A200,  PS3 SuperSlim, NPVR and Plex Server running on Gigabyte Brix (Windows 10 Pro), Sony BDP-S390 BD player, Pioneer AVR, Raspberry Pi running Kodi and Plex, Panasonic 60" 3D plasma, Google Chromecast

System Two: Popcorn Hour A200 ,  Oppo BDP-80 BluRay Player with hardware mode to be region free, Vivitek HD1080P 1080P DLP projector with 100" screen, Denon AVRS730H 7.2 Channel Dolby Atmos/DTS-X AV Receiver, Samsung 4K player, Google Chromecast, Odroid C2 running Kodi and Plex

 

 


ANglEAUT
1237 posts

Uber Geek

Trusted

  #2350515 9-Nov-2019 03:51
Send private message

lchiu7:

 

tchart:

 

I usually just use Gmails SMTP servers. You do need to configure the account to use it though. ...

 

... The SMTP server requires authentication and I am sure I put in the right email address and password (checked it several times) ...

 

Enable less secure apps in the Google / Outlook.com account if you have 2FA enabled.





Please keep this GZ community vibrant by contributing in a constructive & respectful manner.


ANglEAUT
1237 posts

Uber Geek

Trusted

  #2350516 9-Nov-2019 04:04
Send private message

lchiu7:

 

... Next step is to try to work out how to attach files.  

 

As fearandloathing said, the Send-MailMessage cmdlet is supported natively in PowerShell and has the -Attachments parameter for exactly this purpose.

 

Or you can have Stack Overflow tell you (9 years ago).





Please keep this GZ community vibrant by contributing in a constructive & respectful manner.


 1 | 2
Filter this topic showing only the reply marked as answer View this topic in a long page with up to 500 replies per page Create new topic





News »

Nanoleaf enhances lighting line with launch of Triangles and Mini Triangles
Posted 17-Oct-2020 20:18


Synology unveils DS16211+
Posted 17-Oct-2020 20:12


Ingram Micro introduces FootfallCam to New Zealand channel
Posted 17-Oct-2020 20:06


Dropbox adopts Virtual First working policy
Posted 17-Oct-2020 19:47


OPPO announces Reno4 Series 5G line-up in NZ
Posted 16-Oct-2020 08:52


Microsoft Highway to a Hundred expands to Asia Pacific
Posted 14-Oct-2020 09:34


Spark turns on 5G in Auckland
Posted 14-Oct-2020 09:29


AMD Launches AMD Ryzen 5000 Series Desktop Processors
Posted 9-Oct-2020 10:13


Teletrac Navman launches integrated multi-camera solution for transport and logistics industry
Posted 8-Oct-2020 10:57


Farmside hits 10,000 RBI customers
Posted 7-Oct-2020 15:32


NordVPN starts deploying colocated servers
Posted 7-Oct-2020 09:00


Google introduces Nest Wifi routers in New Zealand
Posted 7-Oct-2020 05:00


Orcon to bundle Google Nest Wifi router with new accounts
Posted 7-Oct-2020 05:00


Epay and Centrapay partner to create digital gift cards
Posted 2-Oct-2020 17:34


Inseego launches 5G MiFi M2000 mobile hotspot
Posted 2-Oct-2020 14:53









Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.


Support Geekzone »

Our community of supporters help make Geekzone possible. Click the button below to join them.

Support Geezone on PressPatron



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.

Alternatively, you can receive a daily email with Geekzone updates.