Welcome to ServerForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Send email from Powershell RC?

 
   Windows Server (Home) -> Windows Server Scripting RSS
Next:  Restart service after coming back from standby/hi..  
Author Message
MadBison

External


Since: Jul 25, 2006
Posts: 1



(Msg. 1) Posted: Tue Jul 25, 2006 5:40 am
Post subject: Send email from Powershell RC?
Archived from groups: microsoft>public>windows>server>scripting (more info?)

Hello

I would like to send an email from PowerShell. I have tried a huge
number of things, and nothing works.

I need to use an SMTP server out on the web. I could potentially set up
IIS locally, and use it to forward the emails to my ISP's SMTP server,
but would rather not if I can get away with it.

I do need to send the uid and password to the SMTP server, and would
prefer to send them securely.

This is what I got to, but there are really too many problems with
this. The start of the problems is that the System.Net namespace cannot
be imported. It works with System.Web, but not System.Net.

[Reflection.Assembly]::LoadWithPartialName("System.Net")
$objSmtpClient = new-object [System.Net.Mail].SmtpClient
$objSmtpClient.Host = "mail.myisp.com"
$objSmtpClient.Port = 25
$CredCache = new-object [System.Net].CredentialCache
$uri = New-Object [System].Uri("mail.myisp.com")
$NetCred = New-Object [System.Net.NetworkCredential].("uid", "pwd")
$CredCache.Add($uri, "Basic", $NetCred )
$objSmtpClient.Credentials = $CredCache
\$objMessage = new-object System.Net.Mail.MailMessage
$objMessage.From = "me@hisdomain.com"
$objMessage.To.Add("me@hisdomain.com")
$objMessage.Subject = "Test Subject"
$objMessage.IsBodyHtml = $False
$objMessage.Body = "Test Body"
$objSmtpClient.Send($objMessage)


So does anyone have a working PowerScript code that uses a web based
SMTP server to send email, with secure password exchange to the SMTP
Server?

Thanks
David

 >> Stay informed about: Send email from Powershell RC? 
Back to top
Login to vote
Jonathan Roberts

External


Since: Jun 24, 2006
Posts: 3



(Msg. 2) Posted: Tue Jul 25, 2006 6:40 pm
Post subject: Re: Send email from Powershell RC? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"MadBison" wrote in message

> Hello
>
> I would like to send an email from PowerShell. I have tried a huge
> number of things, and nothing works.
>
> I need to use an SMTP server out on the web. I could potentially set up
> IIS locally, and use it to forward the emails to my ISP's SMTP server,
> but would rather not if I can get away with it.

Does it have to be PowerShell? If not, you might look into Blat.

 >> Stay informed about: Send email from Powershell RC? 
Back to top
Login to vote
kanjist




Joined: Jul 07, 2007
Posts: 1



(Msg. 3) Posted: Sat Jul 07, 2007 9:53 am
Post subject: Re: Send email from Powershell RC? [Login to view extended thread Info.]

Now, we can use .NET Framework 2.0 and 3.0

$mailer = new-object System.Net.Mail.SmtpClient("smtp.xxx.xx.xx")
$mailer.Send("from@xxx.xx.xx","to@xxx.xx.xx","Subject","Body")

http://msdn2.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx
 >> Stay informed about: Send email from Powershell RC? 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Send an email with an attachement - Hi, I have seen the example scripts in the repository for sending a email from a script. This works totally fine as i would expect. I am having trouble attaching a file to the email. I have been trying to use the AddAttachment method but get a object...

send automatic email with attachment without outlook - hi, i´ve got a very special problem. I would like to send emails via script with attachment without outlook (we use notes). Has anyone a script there for me? thx regards alex

send automatic email with attachment without outlook - hi, has anyone a solution to send an automatic mail wiht attachment without outlook (we use lotus notes) thx regards alex

Check free space and send the report by email in percentage - That is possible, because I have one script that send this e-mail but it's not in percentage is on real size and ocupied space, i'm not a scripting guy but I will be very happy if anyone can help me. Thanks in advance

How to run powershell.exe from cmd.exe? - Hi all, Might sound stupid but how can I run powershell.exe from cmd.exe console? I tried the 'start' command, but it just opens up another cmd.exe console window. C:\>start "C:\Programme\Windows PowerShell\v1.0\powershell.exe - NoExit -NoPr...
   Windows Server (Home) -> Windows Server Scripting All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]