Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Sending eMails

Reply
 
Old 10-19-2006   #1 (permalink)
Fabio GRANDE poker.it>


 
 

Sending eMails

Hi all.
I'm wondering if it's possible to send eMails directly from Powershell...

Can You point me in the right direction ?

TIA
FabioG

My System SpecsSystem Spec
Old 10-19-2006   #2 (permalink)
dreeschkind


 
 

RE: Sending eMails

http://groups.google.de/group/micros...f5421e406925f0

--
greetings
dreeschkind

"Fabio GRANDE" wrote:

> Hi all.
> I'm wondering if it's possible to send eMails directly from Powershell...
>
> Can You point me in the right direction ?
>
> TIA
> FabioG

My System SpecsSystem Spec
Old 10-19-2006   #3 (permalink)
Matt Hamilton


 
 

Re: Sending eMails

That seems a bit excessive. How about:

(new-object Net.Mail.SmtpClient -arg
"mailserver.example.com").Send("from@powershell.com", "to@example.com",
"Subject", "Here is some mail from PowerShell.")

dreeschkind wrote:
> http://groups.google.de/group/micros...f5421e406925f0
>
> --
> greetings
> dreeschkind
>
> "Fabio GRANDE" wrote:
>
>> Hi all.
>> I'm wondering if it's possible to send eMails directly from Powershell...
>>
>> Can You point me in the right direction ?
>>
>> TIA
>> FabioG

My System SpecsSystem Spec
Old 10-20-2006   #4 (permalink)
Fabio GRANDE poker.it>


 
 

Re: Sending eMails

Very Good !
Thank You Matt... (I did some improvement to send also attachments...)
Fabio G

My System SpecsSystem Spec
Old 10-20-2006   #5 (permalink)
Fred J.


 
 

Re: Sending eMails

Matt,
I found the .NET Framework Class Library references in the MSDN library
for SmtpClient Class and SmtpClient.Send Method (MailMessage) .
However, can you give me some hints on how you transform that
documentation into the example you showed? Or is there another class
that i missed?

Thank you,
Fred Jacobowitz

Matt Hamilton wrote:
> That seems a bit excessive. How about:
>
> (new-object Net.Mail.SmtpClient -arg
> "mailserver.example.com").Send("from@powershell.com", "to@example.com",
> "Subject", "Here is some mail from PowerShell.")


My System SpecsSystem Spec
Old 10-20-2006   #6 (permalink)
mabster


 
 

Re: Sending eMails

No worries, Fred.

The first step is creating an instance of SmptClient, and passing in a
mail server name to its constructor. In C# that'd look like this:

System.Net.Mail.SmtpClient sc = new
System.Net.Mail.SmtpClient("mailserver.example.com")

.... but in PS it's:

new-object Net.Mail.SmtpClient -arg "mailserver.example.com"

(The -arg parameter of new-object is how we pass stuff into an object's
constructor.)

So once we have our object, we just want to call its Send method. In C#
we'd do this:

sc.Send("from@powershell.com", "to@example.com", "Subject", "Here is
some mail from PowerShell.");

.... but in PS we don't even need a variable - we can just use the
instance inline by wrapping it in parentheses, like this:

(new-object Net.Mail.SmtpClient -arg
"mailserver.example.com").Send("from@powershell.com", "to@example.com",
"Subject", "Here is some mail from PowerShell.")

Note that I could have done it on two lines with a variable:

$sc = new-object Net.Mail.SmtpClient -arg "mailserver.example.com"
$sc.Send("from@powershell.com", "to@example.com", "Subject", "Here is
some mail from PowerShell.");

Does that help?

Fred J. wrote:
> Matt,
> I found the .NET Framework Class Library references in the MSDN library
> for SmtpClient Class and SmtpClient.Send Method (MailMessage) .
> However, can you give me some hints on how you transform that
> documentation into the example you showed? Or is there another class
> that i missed?
>
> Thank you,
> Fred Jacobowitz
>
> Matt Hamilton wrote:
>> That seems a bit excessive. How about:
>>
>> (new-object Net.Mail.SmtpClient -arg
>> "mailserver.example.com").Send("from@powershell.com", "to@example.com",
>> "Subject", "Here is some mail from PowerShell.")

>

My System SpecsSystem Spec
Old 10-20-2006   #7 (permalink)
Fred J.


 
 

Re: Sending eMails

mabster,
Yes this does help. Too me the mystery was unmasking the public
constructors in the send method. Now i see they are derived from .NET
Framework Class Library
MailMessage Constructor (String, String, String, String). I am new to
the Net Framework but I finally found the overload list here
http://msdn2.microsoft.com/en-us/lib...ilmessage.aspx
and the declaration here
http://msdn2.microsoft.com/en-us/library/5k0ddab0.aspx

Is this the way to 'dope-out' everything in .Net?

Now I am going to try to add an attachment.

Fred J.



mabster wrote:
> No worries, Fred.
>
> The first step is creating an instance of SmptClient, and passing in a
> mail server name to its constructor. In C# that'd look like this:
>
> System.Net.Mail.SmtpClient sc = new
> System.Net.Mail.SmtpClient("mailserver.example.com")
>
> ... but in PS it's:
>
> new-object Net.Mail.SmtpClient -arg "mailserver.example.com"
>
> (The -arg parameter of new-object is how we pass stuff into an object's
> constructor.)
>
> So once we have our object, we just want to call its Send method. In C#
> we'd do this:
>
> sc.Send("from@powershell.com", "to@example.com", "Subject", "Here is
> some mail from PowerShell.");
>
> ... but in PS we don't even need a variable - we can just use the
> instance inline by wrapping it in parentheses, like this:
>
> (new-object Net.Mail.SmtpClient -arg
> "mailserver.example.com").Send("from@powershell.com", "to@example.com",
> "Subject", "Here is some mail from PowerShell.")
>
> Note that I could have done it on two lines with a variable:
>
> $sc = new-object Net.Mail.SmtpClient -arg "mailserver.example.com"
> $sc.Send("from@powershell.com", "to@example.com", "Subject", "Here is
> some mail from PowerShell.");
>
> Does that help?
>
> Fred J. wrote:
> > Matt,
> > I found the .NET Framework Class Library references in the MSDN library
> > for SmtpClient Class and SmtpClient.Send Method (MailMessage) .
> > However, can you give me some hints on how you transform that
> > documentation into the example you showed? Or is there another class
> > that i missed?
> >
> > Thank you,
> > Fred Jacobowitz
> >
> > Matt Hamilton wrote:
> >> That seems a bit excessive. How about:
> >>
> >> (new-object Net.Mail.SmtpClient -arg
> >> "mailserver.example.com").Send("from@powershell.com", "to@example.com",
> >> "Subject", "Here is some mail from PowerShell.")

> >


My System SpecsSystem Spec
Old 10-20-2006   #8 (permalink)
Fred J.


 
 

Re: Sending eMails

Do Tell!
Thanks,
Fred Jacobowitz
Fabio wrote:
> Very Good !
> Thank You Matt... (I did some improvement to send also attachments...)
> Fabio G


My System SpecsSystem Spec
Old 10-22-2006   #9 (permalink)
IT Staff


 
 

Re: Sending eMails

msdn subscription is a good source of finding various classes and
constructors.

That is why i m now trying to move from vbscript to powershell.

But at time, i still wonder whether i shld create small programs in pure
..net environment (eg vs2005), this is where i m struggling now ...


"Fred J." <swim.instructor@gmail.com> wrote in message
news:1161356541.004369.26930@i3g2000cwc.googlegroups.com...
> mabster,
> Yes this does help. Too me the mystery was unmasking the public
> constructors in the send method. Now i see they are derived from .NET
> Framework Class Library
> MailMessage Constructor (String, String, String, String). I am new to
> the Net Framework but I finally found the overload list here
> http://msdn2.microsoft.com/en-us/lib...ilmessage.aspx
> and the declaration here
> http://msdn2.microsoft.com/en-us/library/5k0ddab0.aspx
>
> Is this the way to 'dope-out' everything in .Net?
>
> Now I am going to try to add an attachment.
>
> Fred J.
>
>
>
> mabster wrote:
>> No worries, Fred.
>>
>> The first step is creating an instance of SmptClient, and passing in a
>> mail server name to its constructor. In C# that'd look like this:
>>
>> System.Net.Mail.SmtpClient sc = new
>> System.Net.Mail.SmtpClient("mailserver.example.com")
>>
>> ... but in PS it's:
>>
>> new-object Net.Mail.SmtpClient -arg "mailserver.example.com"
>>
>> (The -arg parameter of new-object is how we pass stuff into an object's
>> constructor.)
>>
>> So once we have our object, we just want to call its Send method. In C#
>> we'd do this:
>>
>> sc.Send("from@powershell.com", "to@example.com", "Subject", "Here is
>> some mail from PowerShell.");
>>
>> ... but in PS we don't even need a variable - we can just use the
>> instance inline by wrapping it in parentheses, like this:
>>
>> (new-object Net.Mail.SmtpClient -arg
>> "mailserver.example.com").Send("from@powershell.com", "to@example.com",
>> "Subject", "Here is some mail from PowerShell.")
>>
>> Note that I could have done it on two lines with a variable:
>>
>> $sc = new-object Net.Mail.SmtpClient -arg "mailserver.example.com"
>> $sc.Send("from@powershell.com", "to@example.com", "Subject", "Here is
>> some mail from PowerShell.");
>>
>> Does that help?
>>
>> Fred J. wrote:
>> > Matt,
>> > I found the .NET Framework Class Library references in the MSDN library
>> > for SmtpClient Class and SmtpClient.Send Method (MailMessage) .
>> > However, can you give me some hints on how you transform that
>> > documentation into the example you showed? Or is there another class
>> > that i missed?
>> >
>> > Thank you,
>> > Fred Jacobowitz
>> >
>> > Matt Hamilton wrote:
>> >> That seems a bit excessive. How about:
>> >>
>> >> (new-object Net.Mail.SmtpClient -arg
>> >> "mailserver.example.com").Send("from@powershell.com",
>> >> "to@example.com",
>> >> "Subject", "Here is some mail from PowerShell.")
>> >

>



My System SpecsSystem Spec
Old 10-22-2006   #10 (permalink)
Jim Holbach


 
 

Re: Sending eMails

Fred -

Here's a couple ways I know of to ferret out info:

PS> $a = new-object Net.Mail.SmtpClient
PS> $a.send.OverloadDefinitions
System.Void Send(String from, String recipients, String subject, String body)
System.Void Send(MailMessage message)

and

PS> $a.MSDN()

will open a separate browser window in the msdn2.microsoft.com site with the
documentation for the class of the object. In this example, it opened
"http://msdn2.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx".

Hope this helps.

---
Jim Holbach


"Fred J." wrote:

> mabster,
> Yes this does help. Too me the mystery was unmasking the public
> constructors in the send method. Now i see they are derived from .NET
> Framework Class Library
> MailMessage Constructor (String, String, String, String). I am new to
> the Net Framework but I finally found the overload list here
> http://msdn2.microsoft.com/en-us/lib...ilmessage.aspx
> and the declaration here
> http://msdn2.microsoft.com/en-us/library/5k0ddab0.aspx
>
> Is this the way to 'dope-out' everything in .Net?
>
> Now I am going to try to add an attachment.
>
> Fred J.
>
>
>
> mabster wrote:
> > No worries, Fred.
> >
> > The first step is creating an instance of SmptClient, and passing in a
> > mail server name to its constructor. In C# that'd look like this:
> >
> > System.Net.Mail.SmtpClient sc = new
> > System.Net.Mail.SmtpClient("mailserver.example.com")
> >
> > ... but in PS it's:
> >
> > new-object Net.Mail.SmtpClient -arg "mailserver.example.com"
> >
> > (The -arg parameter of new-object is how we pass stuff into an object's
> > constructor.)
> >
> > So once we have our object, we just want to call its Send method. In C#
> > we'd do this:
> >
> > sc.Send("from@powershell.com", "to@example.com", "Subject", "Here is
> > some mail from PowerShell.");
> >
> > ... but in PS we don't even need a variable - we can just use the
> > instance inline by wrapping it in parentheses, like this:
> >
> > (new-object Net.Mail.SmtpClient -arg
> > "mailserver.example.com").Send("from@powershell.com", "to@example.com",
> > "Subject", "Here is some mail from PowerShell.")
> >
> > Note that I could have done it on two lines with a variable:
> >
> > $sc = new-object Net.Mail.SmtpClient -arg "mailserver.example.com"
> > $sc.Send("from@powershell.com", "to@example.com", "Subject", "Here is
> > some mail from PowerShell.");
> >
> > Does that help?
> >
> > Fred J. wrote:
> > > Matt,
> > > I found the .NET Framework Class Library references in the MSDN library
> > > for SmtpClient Class and SmtpClient.Send Method (MailMessage) .
> > > However, can you give me some hints on how you transform that
> > > documentation into the example you showed? Or is there another class
> > > that i missed?
> > >
> > > Thank you,
> > > Fred Jacobowitz
> > >
> > > Matt Hamilton wrote:
> > >> That seems a bit excessive. How about:
> > >>
> > >> (new-object Net.Mail.SmtpClient -arg
> > >> "mailserver.example.com").Send("from@powershell.com", "to@example.com",
> > >> "Subject", "Here is some mail from PowerShell.")
> > >

>
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
SENDING EMAILS Vista mail
Re: sending emails Vista mail
sending emails Vista mail
sending emails Vista mail
Sending emails Vista mail


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46