Link to home
Start Free TrialLog in
Avatar of cawasaki
cawasaki

asked on

send-mailmessage with big body text

hi,

i need to send an email with send-maimessage command.

the body is in 10 lines.

my script get a user name value=$samaccountname, i need in my body text to use this value.


for exemple in line 1:  the user $samaccountname is here.....
.............
...........
.............
...........

are this possible?

thanks
Avatar of cawasaki
cawasaki

ASKER

and in the script i have a for loop to select every Active directory user, so the email message must integrate the for loop
Avatar of Joseph Daly
Yes you should be able to do that.


Send-MailMessage -to "user@email.com" -Subject "Subject" -from sender@email.com -body "$samaccountname" -smtpserver mailserver.com
no, i have a body with 10 line!

in the text body i need to use $samaccountname value!
And that variable is in the body

Send-MailMessage -to "user@email.com" -Subject "Subject" -from sender@email.com -body "$samaccountname" -smtpserver mailserver.com
no and no :)

where is my body text in 10 lines????
maybe if you actually tried explaining what you were trying to do we could figure out what the code needs to be.

But good luck getting other experts to help you when you have such a bad attitude toward those that try to assist.

Good luck buddy.
sorry, its not a bad attitude but my bad english!

here what i need to do with my script:


$datediff = 10

$reportPath = "c:\expire.csv"
$DatePast = (get-date).AddDays($dateDiff)

#Email

$Body = @"

<b>The account $displayname (dont vous êtes le responsable) will expire in $expiration .</b>
<br>
<br>
You need to contact service desk if you still need this account :
<br>
<br>
                - in this address www.test.com
<br>
<br>
                - or by phone in 060606060606
<br>
<br>

blablabalbalablabalablablabalabla..................

"@


$FromAddress = "test@test.com" 
$SMTPServer = "10.10.10.10"



$Expiring = Get-QADUser -AccountExpiresBefore $datePast -AccountExpiresAfter (Get-Date) -sizelimit 0
foreach ($Acct in $expiring) {
	
		$expiration = $acct.accountexpires.tostring()
				if ($acct.Manager -ne $null) {
			$recipients = (Get-QADUser $acct.Manager).mail
			$displayname= $acct.displayname
		
		
		Send-MailMessage -Subject "Account Expiring" -To $recipients -From $FromAddress -SmtpServer $SMTPServer -Body $Body
	} 

else {
		#Assumes file path is valid and file exits.
		$acct.Name +","+$expiration | Out-File -FilePath $reportPath -Append 
	}
}
                                            

Open in new window

the problem in this script is when i receive the email, the value $displayname and $expiration in body text is not good, it not get the value in powerhsell script.

thanks
any helpplz?
ASKER CERTIFIED SOLUTION
Avatar of Ciprian Lozonschi
Ciprian Lozonschi
Flag of Czechia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks its perfect