Hello guys, my first post here and I was hoping someone could help me a little bit. I was working on a powershell project that sends an email with multiple attachements from a directory. Filenames i this directory will change all the time. My code so far is:
#Connection Details$username=jfgs@gmail.com
$password=xxxxxxxx
$smtpServer = smtp.gmail.com
$msg = new-object Net.Mail.MailMessage
#Change port number for SSL to 587
$smtp = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
#Uncomment Next line for SSL
$smtp.EnableSsl = $true
$smtp.Credentials = New-Object System.Net.NetworkCredential( $username, $password )
#From Address
$msg.From = "CMSUPPORT@NFO.no"
#To Address, Copy the below line for multiple recipients
$msg.To.Add(Chris@NFO.no)
#Message Body
$msg.Body=Please See Attached Database Files
#Message Subject
$msg.Subject = DATABASE
write-host "SENDING FILES"
#your file location
$files=Get-ChildItem C:\CM\Send\
Foreach($file in $files)
{
Write-Host Attaching File :- $file
$attachment = New-Object System.Net.Mail.Attachment ArgumentList C:\CM\Send\$file
$msg.Attachments.Add($attachment)
}
$smtp.Send($msg)
$attachment.Dispose();
$msg.Dispose();
write-host "Mail Sent Successfully"
And this code works just fine for this, then I realize that gmail only has 25 MB max attachement size and the files I want to send is around 18 mb.
Anyone have any good ideas to split all files in the directory into seperate emails. i.e one email per file? Having trouble doing so because the filenames keep changing daily.
I am a beginner in this kind of language, but anything will help to get me on the right track :-)
Thank you.