惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Vercel News
Vercel News
N
Netflix TechBlog - Medium
C
Check Point Blog
MyScale Blog
MyScale Blog
The GitHub Blog
The GitHub Blog
Blog — PlanetScale
Blog — PlanetScale
B
Blog RSS Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
WordPress大学
WordPress大学
博客园 - Franky
MongoDB | Blog
MongoDB | Blog
I
InfoQ
Hugging Face - Blog
Hugging Face - Blog
Recent Announcements
Recent Announcements
人人都是产品经理
人人都是产品经理
腾讯CDC
V
Visual Studio Blog
Engineering at Meta
Engineering at Meta
T
The Blog of Author Tim Ferriss
V
V2EX
云风的 BLOG
云风的 BLOG
Microsoft Azure Blog
Microsoft Azure Blog
U
Unit 42
B
Blog

博客园 - David

TFS Server 不存在时,如何去除对应Server的Workspaces 更改已有程序集中的资源 记录:如何删除TFS Project SQL – TRUNCATE vs DELETE SQL – Character data (varchar) 又好久没写东西了! SSIS: Execute SSIS Package in command prompt 【Update】 随感 Windows Workflow Foundation 了解 通过代码将Word 2007 template (dotx)文档转换Word 2007 (docx)文档(续) 通过代码将Word 2007 template (dotx)文档转换Word 2007 (docx)文档 创建Word2007文档而无需安装Word2007 Visual WebGUI - 如何处理MessageBox的DialogResult值 Visual WebGUI - 如何将Dialog的结果传回主窗体 Visual WebGUI Report - 导出到PDF Visual WebGUI 在 Vista IIS 7 中的配置 项目管理片语 - Schedule 在IIS 7设置ASP.NET 1.1(在Vista中使用VS2003) 给儿子的歌!
Powershell: Send mail with attachment 【Update】 - David
David · 2009-07-06 · via 博客园 - David

$sender = "sender@company.com"
$recipient = "recipient@company.com"
$server = "<<SMTP Server>>"

$date = get-date
$file = "D:\test.txt"

$msg = new-object System.Net.Mail.MailMessage
$msg.From = $sender
$msg.To.Add($recipient)
$msg.Subject = "Sending a File " + $date.tostring("yyyy-MM-dd HH:mm:ss")
$msg.Body = "I'm sending a file!"
$fileStream = new-object System.IO.FileStream $file, "Open", "Read"
$ct = new-object System.Net.Mime.ContentType "text/plain; charset=iso-8859-1"
$attachment = new-object System.Net.Mail.Attachment $fileStream, $ct
$msg.Attachments.Add($attachment)
$client = new-object System.Net.Mail.SmtpClient $server
$client.Credentials = new-object System.Net.NetworkCredential "sender@company.com", "<<PASSWORD>>"
$client.EnableSsl = "true"
$client.Send($msg)

如果無需驗證用戶的話,那么可以將 Credential 設置為 [System.Net.CredentialCache]::DefaultNetworkCredentials 。并將 EnaleSsl 設置為 “false” 。