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
Last visit: Thu May 03, 2018 10:23 am

Email field error

Post by smurphy0822 »

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
Last visit: Wed Dec 31, 1969 4:00 pm

Email field error

Post by SAPIEN Support Forums »

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 ***

jvierra
Posts: 14797
Last visit: Sun May 16, 2021 12:59 pm
Answers: 9
Has voted: 3 times
Been upvoted: 9 times

Re: Email field error

Post by jvierra »

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

User avatar
smurphy0822
Posts: 6
Last visit: Thu May 03, 2018 10:23 am

Re: Email field error

Post by smurphy0822 »

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
}

jvierra
Posts: 14797
Last visit: Sun May 16, 2021 12:59 pm
Answers: 9
Has voted: 3 times
Been upvoted: 9 times

Re: Email field error

Post by jvierra »

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

jvierra
Posts: 14797
Last visit: Sun May 16, 2021 12:59 pm
Answers: 9
Has voted: 3 times
Been upvoted: 9 times

Re: Email field error

Post by jvierra »

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