Email field error

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
smurphy0822
Posts: 6
Joined: Sun Mar 03, 2013 12:44 pm

Email field error

Post by smurphy0822 » Wed Mar 04, 2015 9:56 am

I have created a GUI with a textbox where our help desk will be able to included a help desk ticket number, which will then update the ticket.

For this to work correctly, the text needs to be sent in the below format

RE: [Ticket #XXXXX]

I have attempted several time to get this to work with no luck.

What shows up in the email, where RE: [Ticket #XXXXX] should be is the textbox property name. See below.

RE: Ticket:System.Windows.form.text

How do I format so it will send field correctly?

User avatar
SAPIEN Support Forums
Posts: 945
Joined: Wed Dec 03, 2014 2:26 pm

Email field error

Post by SAPIEN Support Forums » Wed Mar 04, 2015 9:56 am

This is an automated post. A real person will respond soon.

Thank you for posting, smurphy0822.

Here are some hints to help you get an accurate and complete answer to your question.

Ask in the best forum: If you asked in the wrong forum, just copy your question to the right forum.

Anticipate follow-up questions!

Did you remember to include the following?
  • 1. Product, version and build
    2. 32 or 64 bit product
    3. Operating system, e.g. Windows 7 64 bit.
    4. Attach a screenshot, if applicable
    5. Attach logs, crash reports, etc., in a ZIP file
If not, please take a moment to edit your original post or reply to this one.

*** Make sure you do not post any licensing information ***

User avatar
jvierra
Posts: 13736
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Email field error

Post by jvierra » Wed Mar 04, 2015 10:18 am

We can't guess without seeing the code you are using to create the string.

User avatar
smurphy0822
Posts: 6
Joined: Sun Mar 03, 2013 12:44 pm

Re: Email field error

Post by smurphy0822 » Wed Mar 04, 2015 11:59 am

Here is the code

Function SendUnlockEmail([string]$x, [string]$y, [int]$z=0, [string]$smtpServer) {
if ($z -gt 0) #you did input a ticket #. Send email to SpiceWorks helpdesk
{
$to = "helpdesk@YourCompany"
$subject = "RE: [Ticket #$z]"
}
$from = $y
$body = $user.cn + ",

Users account has been Off-Boarded per HR's request.

"Closed by + $env:USERNAME + "
#assign to $y
#add 10m
#due in 1 business day
#category User Account"

Send-MailMessage -To $to -From $from -Cc $from -Subject $subject -Body $body -SmtpServer $smtpServer
Write-Host
The user" $user.Name "has successfully been unlocked and an email has been sent to $to.

# end function SendUnlockEmail
}

User avatar
jvierra
Posts: 13736
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Email field error

Post by jvierra » Wed Mar 04, 2015 12:09 pm

You fail to show how you are calling this function. The function has no textboxes in it.

User avatar
jvierra
Posts: 13736
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Email field error

Post by jvierra » Wed Mar 04, 2015 1:57 pm

This will get you closer to something that works:
PowerShell Code
Double-click the code block to select all.
#template 
$body=@'
	{0}
    Users account has been Off-Boarded per HR's request.
   	Closed by {1}
   	#assign to {2} 
   	#add 10m
   	#due in 1 business day
   	#category User Account
'@


if($TextBox.Text -notmatch '\d{5}'){
    #you did input a ticket
}else{
    #Send email to SpiceWorks helpdesk
	$mailprops=@{
		To='helpdesk@YourCompany'
		From=$y
		Cc=$from
		Subject=('RE: [Ticket #{0}' -f $Textbox1.Text)
		Body=($template -f $user.cn,$y,$z)
		SmtpServer=$smtpServer
	}
	Send-MailMessage @mailprops
	Write-Host 'The user $($user.Name) has successfully been unlocked and an email has been sent to $to."
}

Locked