Powershell scripting to send emails based on events in event viewer **PROBLEM IS SENDING attachment of log**

$emailFrom = "[email protected]"
$emailTo = "[email protected]"
$subject = "$env:COMPUTERNAME : A VM was successfully migrated."
$body = "$env:COMPUTERNAME : A VM was successfully migrated."
$smtpServer = "smtp.domain.com"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $body)
this is a template of a ps1 script i wrote. This will send the above email based on a specific event ID for the microsoft failover cluster / operational, say ID 5143 for example. My question is how do i include in that script to also include a copy of the
log for that event ID in the body of the email ?

You problem with this code is that the SMTPClient send method does not handle attachements.
Instead, try creating the message, using the system.net.mail.mailmessage class to create the message.Then create a mail attachment. Finally, add the attachment to the message. This allows you to craate an attachment, then use the SMTPServer object to send
that mail.
The code should look something like this:
$To      = "[email protected]"
$From    = "[email protected]"
$Subject = "Using the .NET SMTP client."
$Body    = "Using this .NET feature, you can send an e-mail message from an application very easily."
# Create mail message
$Message = New-Object System.Net.Mail.MailMessage $From, $To, $Subject, $Body
$AttchmentText = get-content C:\foo\aaaaaaa.txt  # or whatever
# Now create Attachement content type
$ct = new-object System.Net.Mime.Contenttype
$ct.name = 'text/plain'
# Now create an attachment of that type
$attachment = [System.Net.Mail.Attachment]::CreateAttachmentFromString($attchmenttext,$ct)
# Next add Attachment to the message
$message.Attachments.Add($attachment)
# and now create smtp server
$smtpServer = "COOKHAM8"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($message)
I tested this script on my system and it works. You may need to play around a bit with the attachment, in terms of content type, etc.
Thomas Lee <[email protected]>

Similar Messages

  • Sending email-based newsletters

    Is there a way to send email-based newsletters using Mail. The newsletter has been designed in a popular WYSIWYG editor. I know there are lots of dos and dont attached to designing them and thats not what Im interested in learning. Everyone discusses sending them using outlook and entourage but rarely ever Mail - can it be done and how?

    If you mean a newsletter composed with HTML then the answer is yes.
    RTF with Tiger Mail is really HTML but Mail does not include an HTML composer/editor.
    Save the completed HTML document created by the editor of choice.
    Open the saved document with Safari.
    At the Safari menu bar, go to File and select Mail Contents of This Page.
    The document rendered with Safari will be copied to a new Mail.app message which will be sent in its entirety.

  • TS3899 I have set up two email accounts on my iphone4, one with tiscali, my ISP, and the other on gmail. I am able to receive emails on both accounts, and can send emails from my gmail account, but am "Unable to Send Email" from my tiscali (talktalk) acco

    I have set up two email accounts on my iphone4, one with tiscali, my ISP, and the other on gmail. I am able to receive emails on both accounts, and can send emails from my gmail account, but am "Unable to Send Email" from my tiscali (talktalk) account. I get the error message "A copy has been placed in your Outbox. The sender address "name"@tiscali.co.uk was rejected by the server".

    Hi apmichael,
    If you are having issues sending email from one of your mail accounts on your iPhone, you may find the following article helpful:
    iOS: Troubleshooting Mail
    http://support.apple.com/kb/ts3899
    Regards,
    - Brenden

  • On my Mac Pro, when I send emails, it always gives me the option of adding an attachment with a paper clip. Today, the paperclip has vanished. What do I do ?

    On my Mac Pro, when I send emails, it always gives me the option of adding an attachment with a paper clip.
    Today, the paperclip has vanished. What do I do ?
    Simon

    http://www.apple.com/support/mail

  • I can no longer send emails from my mac yahoo business account, but can send them directly from yahoo. just not from mac mail. I've been able to send emails perfectly fine until today. Help!

    I can no longer send emails from my mac yahoo business account, but can send them directly from yahoo. just not from mac mail. I've been able to send emails perfectly fine until today. I've been on the phone with yahoo mail and they've verified that my account settings are correct and I can send email from yahoo. I can receive emails via Mac mail, but just can't send them. An error message appears that says:
    "Sending the message content to the server failed." I can't send emails from my Mac desktop, iphone or ipad. Any suggestions! Help! I'm a Mac rookie and so frustrated! Thanks.

    Please read and begin using Can receive email, but not send email. I had a similar issue with Comcast mail (could receive by not send) and found my answer in this letter. For me it took resetting the outgoing mail and telling the system to use a password when sending outgoing mail. If you need help with that please advise and I'll tell you where to look. 

  • I can't send emails via mail. I can receive but not send. I have set up gmail on mail. Any ideas?

    I can't send emails via mail. I can receive but not send. I have set up gmail on mail. Any ideas? No problems with the set up previously to this.

    Go to Mail Preferences- Accounts and confirm you are providing Gmail what they require to send and receive mail. And DON'T specify Secure Socket Layer. Some mail accts don't like SSL
    Good Luck to you.

  • On my iPad I can only send email and messages to apple products.how can I send and receive from other devices other than Apple?

    On my iPad I can only send email and messages to apple products.how can I send and receive from other devices other than Apple?

    Vallakat wrote:
    On my iPad I can only send email and messages to apple products.
    There is a huge difference between sending email and sending messages.
    Yes, I believe you when you say you can only send messages to other Apple products.  The iPad is not a telephone, and therefore, it cannot text message.  It can only iMessage, which means it can send and receive messages to/from other Apple products if they are on WiFi or an iMessage capable cellular network.
    Email, however, is a whole different category.  I don't really think you can only exchange email with other Apple products only.  Make sure you have correctly identified the symptoms.

  • Send email based on the date

    Hi,
    Does any one know how to send emails automatically based on a date. For example in the database we have birth days of all employees. All the employee details are being maintained using a JSF web application. An email has to be sent as birthday reminder. If any one has any ideas as to how to accomplish this from a webapplication or database please let me know.
    Thanks a lot,
    HeMan

    If U are usingOracle db, then there is a plsql package called ut_mail. It has a procedure that sends emails :
    utl_mail.send(sender => 'myName',
    recipients => '[email protected]',
    subject => myTopic',
    message => 'myMessage',
    mime_type=>'text/plain; charset=ISO-8859-2'); If U want to do it in java, write application and use JavaMail.
    Martin

  • Send Email based on Approval Status

    I'm working on a SharePoint workflow in which data can be entered into a form and an email is then send to a supervisor for approval. I have this working successfully. Next, if this information is approved an email will be sent to one email address,
    if it is rejected it will be send to a different email address. This what I'm having trouble figuring out. What is the best way to accomplish this? I'm using SharePoint online via Office 365 and SharePoint Designer 2013 to create the workflows. I'm
    pretty new to SharePoint so I apologize if this is a simple task. Thanks.

    Hi rdoss,
    You can refer the below thread
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/8e637216-b277-448a-8656-0d73c920e2cb/trying-to-send-email-when-a-content-is-approvedrejected?forum=sharepointcustomizationprevious
    Similar to send notification section in the above thread, based on workflow status you send the email to the respective recipient. 
    My Blog- http://www.sharepoint-journey.com|
    If a post answers your question, please click Mark As Answer on that post and Vote as Helpful

  • How do I set up iPhoto '11 version 9.2.1 to send emails with medium/Large/actual size? I try sending photos to a publisher and iPhoto automatically shrinks them to about 40 kB.  Publisher needs between 0.5 and 7 MB.  My ISP has a limit of 12MB

    How can I get to email photos at higher resolution?
    My "iPhoto" or "Mail" automatically reduces photos to about 40 KB .
    My photos, taken with a  common Panasonic Lumix DMC-TZ20 include flora which I send to a publisher.
    I am fairly new to my MacBook (Mac S X Version 10.6.8).  I have been using it for a year.
    I found I could not successfully send Large or Full size photos.
    A few days ago I downloaded a new version of iPhoto (iPhoto '11 version 9.2.1).
    Again, although I get the option of choosing to send small/medium/large//full size photos, it actually only sends them as "Small" (ie about 40kb) which is useless to publish.  If I drag a picture onto the desktop (where my EXIF tells me it is full size) then attach it to an email by dragging, againg the sent email is at "small" size ~40KB).
    My ISP (Westnet) tells me that their maximum accepted size is 12 MB.
    I suspect that I have failed to set up iPhoto for this purpose.  (I am well into retirement but, although geriatric, did study University Physics about half a century ago)

    Also, just a note.   iMac PPC is about iMacs that were available up to early 2006.    iMac Intel is for iMacs that were made available early in to 2006 to present.  Forums for what you have in your profile include:
    https://discussions.apple.com/community/mac_os/mac_os_x_v10.6_snow_leopard
    https://discussions.apple.com/community/ilife/iphoto
    https://discussions.apple.com/community/notebooks/macbook
    Please consider posting and reviewing those locations in the future when you have a question that pertains to one of those products.  You'll much more likely get a resposne then.   This is a user to user forum, and you have to seek knowledge in the areas that are most likely to have the topic of your interest.

  • I have 2 email accounts the second one i have only recently added, i have sent one email from my second account but i cant seem to send anymore, it says "cant send email with selected server" i am still able to send emails from my first account. Any ideas

    I have 2 email accounts, the second i only just recently added, i was able to send an email from this account after i added the account but am not able to send anymore emails. It says "unable to send email with selected server" there are no other servers to choose from. please help! TIA

    Hi apmichael,
    If you are having issues sending email from one of your mail accounts on your iPhone, you may find the following article helpful:
    iOS: Troubleshooting Mail
    http://support.apple.com/kb/ts3899
    Regards,
    - Brenden

  • When sending email I get this error message: An error occurred sending mail: The mail server sent an incorrect greeting: Cannot establish SSL with SMTP server

    This issue has popped up before then went away after I switched to SSL setings as suggested by my website host. Or...was it pure coincidence? Same problem today and I haven't made any changes since the above mentioned and have had many successful emails sent. Can't reply or send emails and the draft gets removed from the draft folder even if I saved it before hitting send. Thank you!

    Thank you Matt. I'm sure this will be frustrating ...but the more I think about this problem there more info I have to share. The emails I write that do not get sent do end up in my "sent" folder but never reach the recipient. And, most perplexing, the issue/problem is sporadic. It was coming and going before I switched over to the SSL/TLS option in T-bird. And...since the switch it has reappeared and disappeared. I have made zero changes other than the above mentioned. I did get a security update today for T-bird perhaps this will help?
    I read your link, thank you.
    I obviously don't understand how these systems work. I'm baffled how an issue like this can come and go...

  • Ever since installing "silverlight" as requested by computer message I have been unable to send emails on firfox...not a problem with safari.

    Got a computer message about upgrading to something called silverlight. A message now covers bar for reply, send, forward, etc. and I can't send emails on firefox. This is not a problem when I use Safari.

    Not enough free space on the startup disk can slow the system down.
    Right or control click the MacintoshHD icon. Click Get Info. In the Get Info window you will see Capacity and Available. Make sure there's a minimum of 15% free disk space.
    For startup issues...  open System Preferences > Users & Groups - Login Items. Delete any apps listed there then restart your mac.
    And disable the Lion "resume" feature.
    Open System Preferences > General
    Deselect:   Restore windows when quitting and re-opening apps
    And Spotlight may be indexing... you can turn that off > Turning Off Spotlight | Mac Tricks And Tips

  • Can't send email. Is it an IP address problem?

    I'm using suddenlink.com as my server. I can get online can get email through Apple main, but not send email. Suddenlink tech support verified my settings are correct and said it's an Apple mail problem. But I switched to some software called Newsletter and tried again and still can't send. The log said suddenlink was refusing the connection from my ip address, and gave the ip address. But that's not my ip address. So I ran Network Utility and used traceroute and it traced that ip address to my real ip address. I hope that made sense. The only thing I can think of is that my computer is sending the wrong ip address, or some sub-address, when I try to use suddenlink mail. This has been going on since I moved six months ago. I need to send through Apple mail to send html email for my business, so this is really killing me. Thanks for ANY advice.

    Hi Dopiii,
    I doubt it's an IP issue, but cannot say for certain as I don't know anything about suddenlink.com
    Typically, one's inability to send mail is because of a port issue, not IP address issue. When you go to send a message, you send it via an SMTP server (smtp.suddenlink.com) for example might be your SMTP. SMTP typically uses port 25, but there are several ISPs which block port 25 to reduce spam traffic on their network as that port can often be used as a relay port.
    http://www.postcastserver.com/help/Port25Blocking.aspx
    Other SMTP ports are 465 and 587 and some ISPs will require authenticated SMTP in addition to a custom port.
    With all of that being said (and I realize it's a lot of tech jargon), I doubt Apple Mail is the problem. One thing you might want to do is take your machine into an Apple Store and see if they can assist you. Another option would be to signup for a free Gmail account, configure Gmail for Apple Mail and try using Gmail's SMTP (over port 587). Because if that works and the other email doesn't, the issue is not with Apple Mail.

  • Sending emails from iPad using 3 network? Problems

    Hi,
    I have an issue with my iPad sending emails via the 3 network. When I change the smtp server port to 587, it verifys and all looks well.
    However, when you go back into the setup screen the server port has reverted to 25! Help.

    MartinRowe57 wrote:
    The smtp.mail.yahoo.com fix will l not work when BT and Yahoo go their separate ways. We need BT to come up with a permanent solution
    I did mention that in the post. The permanent solution will be to use mail.btinternt.com SMTP server.

Maybe you are looking for

  • Ipod v2.3 not being recognised by itunes

    when I plug my ipod in itunes will not recognise it, then it opens up a window called autorun with a torch searching for something. Nothing ever gets found and my device manager recognises it as an ipod device. I have done the 5rs on the support page

  • ADD new fields in OIM to provisioned on OID

    Hello, I need a confirmation about these steps to add a new field to provisioned to OID. new field called slClient did i need to do all these steps ? 1- Resource Object OID User --> Object Reconciliation (tab), add Field: sl Client --> String Xellera

  • Bulk batch Jax-WS web services and memory concerns

    I have a requirement to create a web service client to upload 150,000+ records from our database.  My main question is whether others are creating web services to process bulk data and how they handle memory concerns. I began with the standard API, p

  • Smartview Question

    Hi, Kinda new to Smartview as I'm an old Essbase Add In guy. Anyways a few questions. I have a spreadsheet with multiple tabs. In the POV box that floats around I have dragged Scenario, Version, Period into it. I also moved it to the top of the sheet

  • Email sent but not found in the Sent folder

    I just sent an email with Mail on my new Mavericks OS, I heard the "sent" sound, yet the email is not visible in the "Sent" folder and no error is displayed. Where is it? Has it really been sent? 15 minutes have passed now, but it is still not visibl