Using LinkLabel to send email with details

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.
This topic is 6 years and 3 weeks old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
ctrlaltdel
Posts: 12
Last visit: Mon Mar 18, 2024 4:23 pm

Using LinkLabel to send email with details

Post by ctrlaltdel »

I would like to create a LinkLabel to send an email which will open a new email and populate the To, Subject and Body fields. Information to be gathered, current logged on user and computer name. I know how to use WMI to gather information about the computer, just need to know how to integrate it all into the linklabel.

Thanks
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Using LinkLabel to send email with details

Post by jvierra »

What do you mean "integrate into LinkLabel"??

$linklabel1.Text = $env:COMPUTERNAME + ':' + $env:USERNAME
User avatar
ctrlaltdel
Posts: 12
Last visit: Mon Mar 18, 2024 4:23 pm

Re: Using LinkLabel to send email with details

Post by ctrlaltdel »

I want the link label to open an outlook email and prepoulate the fields with information that I provide

To: address@domain.com
Subject: New Email from $ENV:UserName on $ENV:ComputerName

Body: Please type your message below
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Using LinkLabel to send email with details

Post by jvierra »

You would have to code that in the click event and in the COM code create a new mail message and populate the fields then display the mail item. There are a number of ways to do this. Here is one:

https://social.technet.microsoft.com/Fo ... powershell
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: Using LinkLabel to send email with details

Post by localpct »

Why open outlook?
  1. Send-MailMessage -Body "" -to "" -From "" -Subject "" -SmtpServer ""
RARLINX1
Posts: 9
Last visit: Mon Feb 20, 2023 1:34 pm

Re: Using LinkLabel to send email with details

Post by RARLINX1 »

so something like this:
  1. $linklabel1_LinkClicked=[System.Windows.Forms.LinkLabelLinkClickedEventHandler]{
  2.     $Outlook = New-Object -ComObject Outlook.Application
  3.     $Mail = $Outlook.CreateItem(0)
  4.     $Mail.To = "person@company.com"
  5.     $Mail.bcc = "person2@company.com"
  6.     $Mail.cc = "person3@company.com"
  7.     $Mail.Subject = "New Email from $ENV:UserName on $ENV:ComputerName"
  8.     $Mail.Body = "Hello User, `nThis is an automated message!`nThe following user: $ENV:UserName has broken their device: $ENV:ComputerName and produced Error code $YourError`n`nPlease Send Help!"
  9.     $Mail.Importance = 2 # 0=Low 1=normal 2=high
  10.     $Mail.Display() # $Mail.Send() $Mail.Save()
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Using LinkLabel to send email with details

Post by jvierra »

The request was to open a mail item in Outlook. This is common thing for automating support requests. We set the mail item To and Subject plus adding attachments. The message is then displayed so the user can add comments.

The link I posted does this in a few lines. It is familiar to the user and we do not have to know about mail servers and the users email address. This is all populated by Outlook. User adds comments and attaches other files and hits "Send". Mail gone. All in 6 or 7 lines of code.
This topic is 6 years and 3 weeks old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked