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.




5169 posts

Uber Geek

Trusted

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

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
2657 posts

Uber Geek

Trusted
Lifetime subscriber

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

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

1019 posts

Uber Geek


  # 2350093 8-Nov-2019 10:53
One person supports this post
Send private message quote this post

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.


 
 
 
 


947 posts

Ultimate Geek


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

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.


1779 posts

Uber Geek


  # 2350096 8-Nov-2019 10:57
One person supports this post
Send private message quote this post

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


2359 posts

Uber Geek

Lifetime subscriber

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

Run Postfix on an RPi to relay to Spark.





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


1543 posts

Uber Geek

Trusted

  # 2350103 8-Nov-2019 11:07
2 people support this post
Send private message quote this post

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
 }

 

 


1019 posts

Uber Geek


  # 2350106 8-Nov-2019 11:11
One person supports this post
Send private message quote this post

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.


 
 
 
 


4555 posts

Uber Geek

Trusted

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

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


145 posts

Master Geek

Lifetime subscriber

  # 2350132 8-Nov-2019 12:54
One person supports this post
Send private message quote this post

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
    #>




5169 posts

Uber Geek

Trusted

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

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

 

 




5169 posts

Uber Geek

Trusted

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

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

 

 


4555 posts

Uber Geek

Trusted

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

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




5169 posts

Uber Geek

Trusted

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

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

 

 


1031 posts

Uber Geek

Trusted

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

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.


1031 posts

Uber Geek

Trusted

  # 2350516 9-Nov-2019 04:04
Send private message quote this post

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



Twitter and LinkedIn »



Follow us to receive Twitter updates when new discussions are posted in our forums:



Follow us to receive Twitter updates when news items and blogs are posted in our frontpage:



Follow us to receive Twitter updates when tech item prices are listed in our price comparison site:





News »

Microsoft launches first Experience Center worldwide for Asia Pacific in Singapore
Posted 13-Nov-2019 13:08


Disney+ comes to LG Smart TVs
Posted 13-Nov-2019 12:55


Spark launches new wireless broadband "Unplan Metro"
Posted 11-Nov-2019 08:19


Malwarebytes overhauls flagship product with new UI, faster engine and lighter footprint
Posted 6-Nov-2019 11:48


CarbonClick launches into Digital Marketplaces
Posted 6-Nov-2019 11:42


Kordia offers Microsoft Azure Peering Service
Posted 6-Nov-2019 11:41


Spark 5G live on Auckland Harbour for Emirates Team New Zealand
Posted 4-Nov-2019 17:30


BNZ and Vodafone partner to boost NZ Tech for SME
Posted 31-Oct-2019 17:14


Nokia 7.2 available in New Zealand
Posted 31-Oct-2019 16:24


2talk launches Microsoft Teams Direct Routing product
Posted 29-Oct-2019 10:35


New Breast Cancer Foundation app puts power in Kiwi women's hands
Posted 25-Oct-2019 16:13


OPPO Reno2 Series lands, alongside hybrid noise-cancelling Wireless Headphones
Posted 24-Oct-2019 15:32


Waikato Data Scientists awarded $13 million from the Government
Posted 24-Oct-2019 15:27


D-Link launches Wave 2 Unified Access Points
Posted 24-Oct-2019 15:07


LG Electronics begins distributing the G8X THINQ
Posted 24-Oct-2019 10:58



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.