Telnet command line

Peter_1985 2,846 Reputation points
2023-03-09T09:34:05.5866667+00:00

Hi,

Is there one example to call one Powershell line from VS project (using C#), and the command line is to telnet one existing Email account to send out a message?

Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
{count} votes

Answer accepted by question author
  1. Minxin Yu 13,506 Reputation points Microsoft External Staff
    2023-03-10T06:17:16.5766667+00:00

    Hi, Peter_1985

    The snippet below works for me. For your reference: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/send-mailmessage?view=powershell-7.3

                PowerShell ps = PowerShell.Create();
                ps.AddScript("$UserName = '******@XXX.com'");
                ps.AddScript("$Password = ConvertTo-SecureString passwordtoken -AsPlainText –Force");
                ps.AddScript("$cred = New-Object System.Management.Automation.PSCredential($UserName,$Password) ");
                ps.AddScript("Send-MailMessage -From '******@XXX.com' -To '******@XXX.com' -Subject 'Test mail' -SmtpServer 'smtp.XXX.com'  -Credential $cred");
                ps.Invoke();
    

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.