Page 1 of 1

Using LinkLabel to send email with details

Posted: Tue Mar 06, 2018 8: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 8: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 8: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 9: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 6:10 am
by localpct
Why open outlook?

Code: Select all

Send-MailMessage -Body "" -to "" -From "" -Subject "" -SmtpServer ""

Re: Using LinkLabel to send email with details

Posted: Wed Mar 07, 2018 2:24 pm
by luk4mu5
so something like this:

Code: Select all

$linklabel1_LinkClicked=[System.Windows.Forms.LinkLabelLinkClickedEventHandler]{
$Outlook = New-Object -ComObject Outlook.Application
$Mail = $Outlook.CreateItem(0)
$Mail.To = "person@company.com"
$Mail.bcc = "person2@company.com"
$Mail.cc = "person3@company.com"
$Mail.Subject = "New Email from $ENV:UserName on $ENV:ComputerName"
$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!"
$Mail.Importance = 2 # 0=Low 1=normal 2=high
$Mail.Display() # $Mail.Send() $Mail.Save()

Re: Using LinkLabel to send email with details

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