#定义邮件服务器
$smtpServer = "mail.xx.com"
$smtpUser = "sender"
$smtpPassword = "password"
$mail = New-Object System.Net.Mail.MailMessage #定义发件人邮箱地址、收件人邮箱地址
$MailAddress="sender@xx.com"
$MailtoAddress="l1@xx.com" $mail.From = New-Object System.Net.Mail.MailAddress($MailAddress)
$mail.To.Add($MailtoAddress) #定义邮件标题、优先级和正文
$mail.Subject = "Test587";
$mail.Priority = "High"
$mail.Body = "Test Mail"
$smtp = New-Object System.Net.Mail.SmtpClient -argumentList $smtpServer,587 #使用587端口
$smtp.Enablessl = $true #使用TLS加密
$smtp.Credentials = New-Object System.Net.NetworkCredential -argumentList $smtpUser,$smtpPassword
$smtp.Send($mail)

发送html格式邮件

#密码过期提醒发送邮件  -2017-07-18

#定义邮件服务器
$smtpServer = "mail.x.com"
$smtpUser = "user@x.com"
$smtpPassword = "password"
$mail = New-Object System.Net.Mail.MailMessage #定义发件人邮箱地址、收件人邮箱地址
$MailAddress="user@x.com"
$mail.From = New-Object System.Net.Mail.MailAddress($MailAddress)
$mail.IsBodyHtml = $True #定义为HTML格式邮件 #定义邮件标题、优先级和正文
$mail.Subject = "提醒:";
$mail.Priority = "High"
$smtp = New-Object System.Net.Mail.SmtpClient -argumentList $smtpServer,587 #使用587端口
$smtp.Enablessl = $true #使用TLS加密
$smtp.Credentials = New-Object System.Net.NetworkCredential -argumentList $smtpUser,$smtpPassword $MailtoAddress="l@x.com"
$mail.To.Add($MailtoAddress)
$mail.Body = "<html><body><span style='font-size:10.5pt;font-family:宋体'>
您好,
<br><br> &nbsp;&nbsp;&nbsp;&nbsp;您的帐号 密码将会于3天后过期。请尽快修改!
<br><br> &nbsp;&nbsp;&nbsp;&nbsp;修改方法:。
<br><br><br> <img width=146 height=52 alt="""" src=""http://img.x.com/logo.png"" />
<br>-----------------------------------------
<br>这封邮件由管理程序自动生成,请勿直接回复!
</span></body></html>"
$smtp.Send($mail)

$smtp.UseDefaultCredentials = $false 要放在SmtpClient.Credentials之前

If the UseDefaultCredentials property is set to false, then the value set in the Credentials property will be used for the credentials when connecting to the server. If the UseDefaultCredentials property is set to false and the Credentials property has not been set, then mail is sent to the server anonymously.

PowerShell发送邮件(587)的更多相关文章

  1. Windows下PowerShell监控Keepalived

    一.背景 某数据库服务器为CentOS,想要监控Keepalived的VIP是否有问题,通过邮件进行报警,但这台机器不能上外网,现在只能在Windows下通过PowerShell来完成发邮件预警. 二 ...

  2. Python Module_subprocess_调用 Powershell

    目录 目录 前言 Powershell call Python Python call Powershell Powershell发送邮件 最后 前言 使用Python内建的subprocess模块, ...

  3. Powershell检查邮件队列设置阈值,通过html形式进行邮件告警

    为了完善公司的整体邮件质量,博主通过zabbix监控了exchange的所有微软推荐项目,并写了很多powershell来辅佐, 旨在更大程度上提高整体的邮件性能 这篇文章主要是讲通过powershe ...

  4. SQL Server自动化运维系列——监控磁盘剩余空间及SQL Server错误日志(Power Shell)

    需求描述 在我们的生产环境中,大部分情况下需要有自己的运维体制,包括自己健康状态的检测等.如果发生异常,需要提前预警的,通知形式一般为发邮件告知. 在所有的自检流程中最基础的一个就是磁盘剩余空间检测. ...

  5. SQL Server自动化运维系列——监控跑批Job运行状态(Power Shell)

    需求描述 在我们的生产环境中,大部分情况下需要有自己的运维体制,包括自己健康状态的检测等.如果发生异常,需要提前预警的,通知形式一般为发邮件告知. 在上一篇文章中已经分析了SQL SERVER中关于邮 ...

  6. SQL Server自动化运维系列 - 监控磁盘剩余空间及SQL Server错误日志(Power Shell)

    需求描述 在我们的生产环境中,大部分情况下需要有自己的运维体制,包括自己健康状态的检测等.如果发生异常,需要提前预警的,通知形式一般为发邮件告知. 在所有的自检流程中最基础的一个就是磁盘剩余空间检测. ...

  7. 阿里云服务器 centos7 中继邮箱+转发服务 详细配置

    阿里云centos7 邮箱转发服务配置 一.文档编写目的: 网络拓扑图: 阿里云服务器屏蔽掉25端口后,内网服务器如何通过跳板机发送邮件到外网邮箱. 如果是可联网的阿里云机器,可以直接配置mailx使 ...

  8. SQL Server 自动化运维系列 - 监控磁盘剩余空间及SQL Server错误日志(Power Shell)

    需求描述 在我们的生产环境中,大部分情况下需要有自己的运维体制,包括自己健康状态的检测等.如果发生异常,需要提前预警的,通知形式一般为发邮件告知. 在所有的自检流程中最基础的一个就是磁盘剩余空间检测. ...

  9. 使用Powershell 脚本发送邮件乱码问题?

    最近在使用Powershell 编码的时候发现一个问题,只要邮件中有中文字符的邮件执行脚本以后,我们发现收到邮件都是乱码,状况如下: 对比下Powershell脚本,我们将邮件的·ENCODING 加 ...

随机推荐

  1. es-04-mapping和setting的建立

    mapping和setting, 使用java客户端比较难组装, 可以使用python或者scala 这儿直接在kibana中进行DSL创建 1, mapping 创建索引的时候, 可以事先对数据进行 ...

  2. SpringDataJPA快速入门

    访问我的博客 前言 之前在学习 SpringBoot 框架的时候,使用到了 SpringData JPA,但是当时只是简单的查询,没有用到稍微复杂的查询. JPA 的 JPQL 语法规则对于简单的查询 ...

  3. python get请求

    #!/usr/bin/python #-*- coding:UTF-8 -*-#coding=utf-8 import requests import time import hashlib impo ...

  4. B 树、B+ 树、B* 树

    B 树.B+ 树.B* 树 作者:July.weedge.Frankie.编程艺术室出品. 说明:本文从B树开始谈起,然后论述B+树.B*树,最后谈到R 树.其中B树.B+树及B*树部分由weedge ...

  5. APIX招聘

  6. git第六节---git 远程仓库

    远程分支类似于本地分支,是指向远程仓库中的文件的指针. 1.远程分支抓取 @git fetch origin dev :拉取远程dev内容 fetch不会对本地仓库内容进行更新,只更新远端commit ...

  7. POJ 2234 Matches Game (尼姆博弈)

    题目链接: https://cn.vjudge.net/problem/POJ-2234 题目描述: Here is a simple game. In this game, there are se ...

  8. UVa 12657 Boxes in a Line(数组模拟双链表)

    题目链接 /* 问题 将一排盒子经过一系列的操作后,计算并输出奇数位置上的盒子标号之和 解题思路 由于数据范围很大,直接数组模拟会超时,所以采用数组模拟的链表,left[i]和right[i]分别表示 ...

  9. C#使用命令编译代码

    1.在路径%SystemRoot%\Microsoft.NET\Framework\vX.X.X(安装的.net版本号)下找到csc.exe,在cmd窗口cd到该路径下. ps(在该路径下有一个CSC ...

  10. WebForm 【复合控件】

    一 复合控件(取值,赋值用法相近)  RadioButtonList      --单选按钮 (一组列表)  <asp:RadioButtonList ID="RadioButtonL ...