This topic contains 3 replies, has 3 voices, and was last updated by
October 21, 2015 at 5:04 am #31092ParticipantPoints: 0Rank: Member
Situation: I'm an employee at a large University, and have been assigned the task of trying to send financial aid award letters to students, in bulk, based on each student's specific aid qualifications.
Goal: automation of award emails to students.
Proposed Solution: Use of Powershell to send emails to students in an automated fashion. The passing and use of variable values to determine which paragraphs they need to receive in their aid letters.
Emails need to go to the students in HTML format. Emails should be personalized to the students, with their first name at the top.
Dear Michael, Dear Linda, Etc.
Emails need to be 'spruced up' with HTML formatting and look professional and of Vprofessional correspondence quality.
Inclusion of the University logo information at the bottom of the email in some fashion is preferred.
This powershell code appeared to have worked and sends a basic email :
Send-MailMessage -Port 25 -To “Test Student " -From “Financial Aid " -SMTPServer smtp.college.edu -Subject “Testing” -Body “Test Message"
This powershell code also appears to be working:
[string] $data = Get-Content "C:\Users\USER68\Desktop\TargetFile2.txt"
Send-MailMessage -Port 25 -To “Testing Gmail " -From “Testing Technician " -SMTPServer smtp.college.edu -Subject “Testing” -BodyAsHtml $data
Sends over correctly the contents of a datafile.
From there I'm stumped. The next step would be to have another text file, that I read somehow with a powershell command, extract name information of the individual, pass it into an a variable, and personalize the email.
Later on, I would like to read in Boolean logic type values or other types of identifiers (also included in the student list text file) to determine which paragraphs of text to merge into the email that would then be generated to the student.
Help is greatly appreciated. I haven't done any serious programming in years. Have I done it? Yes... I've done programming, C++ and so forth, but it will take a while and some help to get back into the zone, and I'm a complete newbie to powershell, although I do have a background in DOS and general concepts I see carrying over into powershell
October 21, 2015 at 5:55 am #31097ParticipantPoints: 2Rank: Member
Windows PowerShell Best Practices by Ed Wilson Page 551 has an excellent structure for sending an email with PowerShell. you can even use $variable = @" "@ to put som fancy HTML in there passed to a variable then use convert to html in the body..
$Html = @"
Html code goes here forum wont let me put in examples
$to = " "
$from = " "
$subject = " "
$body = $html + other variables
$server = " "
$smtp = New-Object Net.Mail.SmtpClient($server)
$smtp.Send ($from, $to, $subject, $body)
In powershell Deep Dives Jeffrey Hicks chapter 12 goes deeper into building HTML and has great examples for creating a Base 64 image and adding it to html code so you dont have to sent the image with the email. Also if you get the deep dives book all proceeds go to a children's charity.
October 21, 2015 at 7:19 am #31104ParticipantPoints: 0Rank: Member
appreciated. I may have to get that book. I really need to develop an understanding on how to use variables within powershell to insert data into the email, and that's beyond my current knowledge.
Any one else have ideas?
October 21, 2015 at 7:29 am #31106ParticipantPoints: 0Rank: Member
not sure if it was you I replied to a while ago with a similar question on another forum but this article covers strings and variables within strings far better than I could ever explain it. Powershell is very easy in this respect and I don't think you'll find what you want to do to be too difficult.
The topic ‘Advice on structuring a powershell email process’ is closed to new replies.