zoukankan      html  css  js  c++  java
  • 用beidasoft@163邮箱发送电子邮件

    cls;
    function Send-MyEMail {
        <#
            .SYNOPSIS
                用beidasoft@163.com发送邮件
    
            .DESCRIPTION
                用beidasoft@163.com发送邮件
            .PARAMETER  to
                邮件接收者
    
            .PARAMETER  body
                内容
            .PARAMETER  subject
                标题
            .PARAMETER ATTACHMENT
                附件
    
            .EXAMPLE
                PS C:\>Send-MyEMail -to "10086@qq.com" -subject "移动你好" -body "我是联通"
    
            .INPUTS
                System.String,System.Int32
    
            .OUTPUTS
                System.String
    
            .NOTES
                Additional information about the function go here.
    
            .LINK
                about_functions_advanced
    
            .LINK
                about_comment_based_help
    
        #>
        [CmdletBinding()]
        [OutputType([System.Int32])]
        param(
            [Parameter(Position=0, Mandatory=$true)]
            [ValidateNotNullOrEmpty()]
            [System.String]
            $to,
    
            [Parameter(Position=1)]
            [ValidateNotNullOrEmpty()]
            [System.String]
            $subject,
            [Parameter(Position=2)]
            [ValidateNotNullOrEmpty()]
            [System.String]
            $body,
            [Parameter(Position=3)]
            [System.String]
            $attachment
        )
        [String]$local:msg=''
        try {
            #密码加密串
            $script:secureString=ConvertTo-SecureString -String "76492d1116743f0423413b16050a5345MgB8AGQASAB3AEkAQQBSAHoAYgBTAEEAQgByADgAZABhAGsAUQA3ADgAaQBWAFEAPQA9AHwAZAA2ADkANAAxADQAZgA
            1ADUAZABiAGUAMQBmAGEAOAA2AGIAZABkADkANQBjADgAZgBiAGQAMABiADYAOABkADYAYwAyADQAYgA0AGYAZABjADgAMgA4ADcAMAAyAGMAYQAwADQANQA0AD
            QAYgAzADEAOQA5ADkAMQAyADkANQA=" -Key   (1..16)        
            #证书
            $script:credential=New-Object system.Management.Automation.PSCredential("beidasoft",$secureString)
            if($attachment -eq $null  -or $attachment -eq "" ){
                Send-MailMessage  -To $to -Body $body -Subject $subject -From "beidasoft@163.com" -UseSsl -Credential $credential -Encoding utf8 -Port 25 -SmtpServer "smtp.163.com"
                $msg="邮件发送成功!" 
            }
            else{            
                if( test-path $attachment ){                
                    Send-MailMessage  -Attachments $attachment -To $to -Body $body -Subject $subject -From "beidasoft@163.com" -UseSsl -Credential $credential -Encoding utf8 -Port 25 -SmtpServer "smtp.163.com"
                    $msg= "邮件发送成功!附件"+$attachment 
                }
                else{
                    Send-MailMessage   -To $to -Body $body -Subject $subject -From "beidasoft@163.com" -UseSsl -Credential $credential -Encoding utf8 -Port 25 -SmtpServer "smtp.163.com"
                    $msg= "邮件发送成功!附件"+$attachment+"无效"
                }
            }        
            
        }
        catch {
            $msg="出错了"
        }finally{
            'At'+([DateTime]::Now).toString()+' '+$msg|Write-Host -ForegroundColor Green
        }
    };
    Send-MyEMail -to "121354381@qq.com" -subject "移动你好" -body "我是联通" -attachment "d:\s.txt"
  • 相关阅读:
    访问者模式
    oracle触发器简单实用示例
    C#控件交互效果类(也可以用作缩小面板放大,展示更多信息)
    23种设计模式探索C#
    windows快捷操作个人记录(常用)
    C#巧妙使用关键字async/await
    学习的枚举类型,结构以及初步了解数组
    目前学习.net时间让我摸不着头脑的事情
    对C#中几个循环语句的使用,请教
    学习了用控制台显示结果
  • 原文地址:https://www.cnblogs.com/fuckcn/p/3113859.html
Copyright © 2011-2022 走看看