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

6522 posts

Uber Geek
+1 received by user: 543

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/h/wellycbd  PM me and mention GZ to get a 15% discount and no AirBnB charges.


View this topic in a long page with up to 500 replies per page Create new topic

This is a filtered page: currently showing replies marked as answers. Click here to see full discussion.

lchiu7

6522 posts

Uber Geek
+1 received by user: 543

Trusted

  #2350817 9-Nov-2019 17:05
Send private message

Well I solved it with this script

 

 

 

$EmailFrom = "from@outlook.com"
$EmailTo = "to@gmail.com"
$EmailSubject = "Testing with attachments"  

 

$SMTPServer = "smtp.office365.com"
$SMTPAuthUsername = "authuser@outlook.com"
$SMTPAuthPassword = "password"

 

$emailattachment = "<fully qualified path and name>"

 

function send_email {
    $mailmessage = New-Object System.Net.Mail.MailMessage 
    $mailmessage.From = ($emailfrom) 
    $mailmessage.To.Add($emailto)
    $mailmessage.Subject = $emailsubject
    $mailmessage.Body = $emailbody
    $attachment = New-Object Net.Mail.Attachment($emailattachment)
    $attachment = New-Object Net.Mail.Attachment($emailattachment, "text/plain")
     $mailmessage.Attachments.Add($attachment)

 

 

 

    #$mailmessage.IsBodyHTML = $true
    $SMTP = New-Object Net.Mail.SmtpClient($SmtpServer, 587)  
    $SMTP.EnableSsl = $true
    $SMTP.Credentials = New-Object System.Net.NetworkCredential($SMTPAuthUsername , $SMTPAuthPassword) 
    $SMTP.Send($mailmessage)
    $attachment.dispose()
}

 

send_email

 

I did try using Send-MailMessage but it wasn't clear how to send the SMTP server credentials. The -credentials option seems to want to use the local server credentials

 

 

 

Thanks for all the suggestions

 

 





Staying in Wellington. Check out my AirBnB in the Wellington CBD.  https://www.airbnb.co.nz/h/wellycbd  PM me and mention GZ to get a 15% discount and no AirBnB charges.


View this topic in a long page with up to 500 replies per page Create new topic








Geekzone Live »

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



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.