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.


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 
lchiu7

6521 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.




fearandloathing
537 posts

Ultimate Geek
+1 received by user: 206

ID Verified
Lifetime subscriber

  #2351418 11-Nov-2019 09:27
Send private message

lchiu7:

 

 

 

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

 

 

 

 

You can use

 

$user = "user@example.com"
$password = "notmypassword"
$SecPassword = ConvertTo-SecureString $password -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PSCredential ($user, $SecPassword)

 

#Example

 

Connect-EXOPSSession -UserPrincipalName $user -Credential $Cred


TwoSeven
1712 posts

Uber Geek
+1 received by user: 304

Subscriber

  #2351508 11-Nov-2019 11:28
Send private message

Ok, I’ve got to ask.

 

The OP mentioned a small office setup.

 

So I am wondering why OneDrive and not something like Azure Storage.





Software Engineer
   (the practice of real science, engineering and management)
A.I.  (Automation rebranded)
Gender Neutral
   (a person who believes in equality and who does not believe in/use stereotypes. Examples such as gender, binary, nonbinary, male/female etc.)

 

 ...they/their/them...




SirHumphreyAppleby
2942 posts

Uber Geek
+1 received by user: 1863


  #2351511 11-Nov-2019 11:41
Send private message

TwoSeven:

 

So I am wondering why OneDrive and not something like Azure Storage.

 

 

Possibly using the storage provided with an Office 365 subscription.


lchiu7

6521 posts

Uber Geek
+1 received by user: 543

Trusted

  #2351541 11-Nov-2019 12:31
Send private message

Right on the money. There is a local NAS which synchronises automatically to The office365 OneDrive account. But their accounting software requires that the database have daily and monthly backup so they have to be on two different directories on the SAN. I don't know any way of doing that automatically so it's done via nightly and monthly BAT jobs and I want to see the result.




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.


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








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.