Page 1 of 1

Using LinkLabel to send email with details

Posted: Tue Mar 06, 2018 7:43 am
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

Re: Using LinkLabel to send email with details

Posted: Tue Mar 06, 2018 7:53 am
by jvierra
What do you mean "integrate into LinkLabel"??

$linklabel1.Text = $env:COMPUTERNAME + ':' + $env:USERNAME

Re: Using LinkLabel to send email with details

Posted: Tue Mar 06, 2018 7:57 am
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

Re: Using LinkLabel to send email with details

Posted: Tue Mar 06, 2018 8:07 am
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

Re: Using LinkLabel to send email with details

Posted: Wed Mar 07, 2018 5:10 am
by localpct
Why open outlook?
  1. Send-MailMessage -Body "" -to "" -From "" -Subject "" -SmtpServer ""

Re: Using LinkLabel to send email with details

Posted: Wed Mar 07, 2018 1:24 pm
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()

Re: Using LinkLabel to send email with details

Posted: Wed Mar 07, 2018 1:49 pm
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.