Thanks Michael, Is this how I accomplish that: PS D:\> $adTypeText = 2 PS D:\> $objMail = New-Object -comobject "CDO.Message" PS D:\> $objStream = $objMail.GetStream() PS D:\> $objStream.type = $adTypeText PS D:\> $objStream.LoadFromFile( "D:\...\0bfcb7ff01cbf3a500000007.eml" ) PS D:\> $objStream.Flush() PS D:\> foreach( $attach in $objMail.Attachments ) { $attach |Get-Member }
TypeName: System.__ComObject#{cd000021-8b95-11d1-82db-00c04fb1625d} Name MemberType Definition ---- ---------- ---------- AddBodyPart Method IBodyPart AddBodyPart (int) GetDecodedContentStream Method _Stream GetDecodedContentStream () GetEncodedContentStream Method _Stream GetEncodedContentStream () GetFieldParameter Method string GetFieldParameter (string, string) GetInterface Method IDispatch GetInterface (string) GetStream Method _Stream GetStream () SaveToFile Method void SaveToFile (string) BodyParts Property IBodyParts BodyParts () {get} Charset Property string Charset () {get} {set} ContentClass Property string ContentClass () {get} {set} ContentClassName Property string ContentClassName () {get} {set} ContentMediaType Property string ContentMediaType () {get} {set} ContentTransferEncoding Property string ContentTransferEncoding () {get} {set} DataSource Property IDataSource DataSource () {get} Fields Property Fields Fields () {get} FileName Property string FileName () {get} Parent Property IBodyPart Parent () {get} Looks promising:) In the meantime, how do I close the open file handle this code leaves on $fileattachment? $mailer = new-object Net.Mail.SMTPclient($SMTPserver, $SMTPserverport) $msg = new-object Net.Mail.MailMessage($from, $to, $subject, $emailbody) $attachment = new-object Net.Mail.Attachment($fileattachment) $msg.attachments.add($attachment) $mailer.send($msg) I can't cleanup the working directory when I am done until that script exits. Thanks! jlc From: Michael B. Smith [mailto:mich...@smithcons.com] Sent: Wednesday, May 11, 2011 11:19 AM To: NT System Admin Issues Subject: RE: Powershell help I'm not going to say that it can't be done - I don't consider myself a master-developer. But the interfaces don't match. A CDO.Message attachment is (under-the-hood) an IBodyParts enumerated collection of IBodyPart. A Net.Mail attachment is either a URI (which may be a filename) or an IStream object. I don't know how to map an IBodyPart to either an URI or an IStream. See if $attach has a GetStream() interface associated method. If so, you are golden. I'm not at a place I can check right now. Regards, Michael B. Smith Consultant and Exchange MVP http://TheEssentialExchange.com From: Joseph L. Casale [mailto:jcas...@activenetwerx.com] Sent: Wednesday, May 11, 2011 12:05 PM To: NT System Admin Issues Subject: Powershell help I am using Net.Mail.SMTPclient to send an email with an attatchment as Send-MailMessage doesn't allow me to change the port. Before this, I parse an email in a IIS drop folder and extract the attachment (thanks for that Michael). As per Michael's original email: $adTypeText = 2 ... $objMail = New-Object -comobject "CDO.Message" $objStream = $objMail.GetStream() $objStream.type = $adTypeText $objStream.LoadFromFile( "c:\file.eml" ) $objStream.Flush() ... foreach( $attach in $objMail.Attachments ) { $attach.Name } ... $objStream.Close() $objStream = $null $objMail = $null The code my sample script was using to manually attach a file for testing looks like: $attachment = new-object Net.Mail.Attachment($fileattachment) $msg.attachments.add($attachment) where I just $fileattachment = "<some path>" Is there a way to utilize the attachment from Michael's code without first saving it to disc, but simply referencing it in the $attachment? Thanks! jlc ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/> ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com<mailto:listmana...@lyris.sunbeltsoftware.com> with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/> ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com<mailto:listmana...@lyris.sunbeltsoftware.com> with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/> ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin