VMware Cloud Community
VMSavvy
Enthusiast
Enthusiast
Jump to solution

Multiple outputs in one email as attachments!!

Hey I'm back with a query again Smiley Happy

I'm able to get a script run on 4 vcenters..

is there a way to get all the outputs as attachments in a single email?? I don't want 4 emails every day Smiley Sad

VMSavvy.

Reply
0 Kudos
1 Solution

Accepted Solutions
RR9
Enthusiast
Enthusiast
Jump to solution

you can use like below ones...

$att = new-object Net.Mail.Attachment(”E:\filename“)
$att1 = new-object Net.Mail.Attachment(”E:\filename“)
$msg.Attachments.Add($att)
$msg.Attachments.Add($att1)

View solution in original post

Reply
0 Kudos
4 Replies
nnedev
VMware Employee
VMware Employee
Jump to solution

Hi VMSavvy,

I've just found this post http://www.searchmarked.com/windows/how-to-send-an-email-using-a-windows-powershell-script.php

You can find there the following code snipet:

$filename = “logfile.txt”
$smtpServer = “localhost”

$msg = new-object Net.Mail.MailMessage
$att = new-object Net.Mail.Attachment($filename)
$smtp = new-object Net.Mail.SmtpClient($smtpServer)

$msg.From = “somebody@yourdomain.com
$msg.To.Add(”somebody@theirdomain.com”)
$msg.Subject = “Nightly Log File”
$msg.Body = “The nightly log file is attached”
$msg.Attachments.Add($att)

$smtp.Send($msg)

So you can add as many attachments as you like Smiley Happy

If you have any other questions don't hesitate to ask.

Thanks,

Nedko

Regards, Nedko Nedev PowerCLI Development Team
VMSavvy
Enthusiast
Enthusiast
Jump to solution

Thanks Nedko..

I'm using this already.. but I get my output into say $filelocation.. the script runs on 4 different vcenters.. so 4 output files are created.. I think I'll get 4 different emails (correct me if I'm wrong)..

so just thinking to see if I can get something like $files = (a code which can club all the outputs) and put $files into the $att to get one email with 4 attachments..

not sure if I explained clearly..

VMSavvy..

Reply
0 Kudos
RR9
Enthusiast
Enthusiast
Jump to solution

you can use like below ones...

$att = new-object Net.Mail.Attachment(”E:\filename“)
$att1 = new-object Net.Mail.Attachment(”E:\filename“)
$msg.Attachments.Add($att)
$msg.Attachments.Add($att1)

Reply
0 Kudos
VMSavvy
Enthusiast
Enthusiast
Jump to solution

That worked. Thanks all!!

VMSavvy..

Reply
0 Kudos