java ncso发送电邮_如何在Windows中从命令行发送电子邮件(无需额外的软件)

java ncso发送电邮

java ncso发送电邮

image

In Windows there is no way to natively send mail from the Command Prompt, but because PowerShell allows you to use the underlying .Net Framework, you can easily create and send an  e-mail from the command line.

在Windows中,无法从命令提示符本地发送邮件,但是由于PowerShell允许您使用基础的.Net Framework,因此您可以轻松地从命令行创建和发送电子邮件。

Note: I have uploaded a sample over here, due to many requests.

注意:由于许多要求,我已经在此处上传了一个示例

从PowerShell发送电子邮件 (Sending Email From PowerShell)

Note: We decided to use the GMail SMTP Servers for this article, that means you will need a GMail account to send mail using the provided code. However, you could easily hack my script to work with any SMTP Server should you want to.

注意:本文决定使用GMail SMTP服务器,这意味着您将需要一个GMail帐户才能使用提供的代码发送邮件。 但是,如果需要,您可以轻松地破解我的脚本以与任何SMTP服务器一起使用。

The first thing you need to do is fire up PowerShell.

您需要做的第一件事是启动PowerShell。

image

It’s pretty easy to send an e-mail from PowerShell, all you need to do is copy the template we provided and change some of the details.

从PowerShell发送电子邮件非常容易,您所需要做的就是复制我们提供的模板并更改一些详细信息。

$EmailFrom = “yourgmailadress@gmail.com”

$ EmailFrom =“ yourgmailadress@gmail.com”

$EmailTo = “destination@somedomain.com”

$ EmailTo =“ destination@somedomain.com”

$Subject = “The subject of your email”

$ Subject =“您的电子邮件主题”

$Body = “What do you want your email to say”

$ Body =“您希望您的电子邮件说什么”

$SMTPServer = “smtp.gmail.com”

$ SMTPServer =“ smtp.gmail.com”

$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)

$ SMTPClient =新对象Net.Mail.SmtpClient($ SmtpServer,587)

$SMTPClient.EnableSsl = $true

$ SMTPClient.EnableSsl = $ true

$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“usr”, “pass”);

$ SMTPClient.Credentials =新对象System.Net.NetworkCredential(“ usr”,“ pass”);

$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

$ SMTPClient.Send($ EmailFrom,$ EmailTo,$ Subject,$ Body)

You will need to change the following:

您将需要更改以下内容:

  • $EmailFrom = Your GMail address.

    $ EmailFrom =您的GMail地址。

  • $EmailTo = The recipient’s email address.

    $ EmailTo =收件人的电子邮件地址。

  • $Subject = What you want the subject of the mail to say.

    $ Subject =您希望邮件主题说什么。

  • $Body = What you want the main part of the mail to say.

    $ Body =您希望邮件的主要部分说什么。

  • usr = You will need to replace this with your GMail username.

    usr =您将需要用您的GMail用户名替换它。

  • pass = You will need to replace this with your GMail password.

    pass =您需要用您的GMail密码替换它。

Below is an example of me sending mail to myself.

以下是我向自己发送邮件的示例。

Note: For obvious reasons, I removed GMail credentials from the screenshot.

注意:出于明显的原因,我从屏幕快照中删除了GMail凭据。

image

That’s all there is to it.

这里的所有都是它的。

image

翻译自: https://www.howtogeek.com/120011/stupid-geek-tricks-how-to-send-email-from-the-command-line-in-windows-without-extra-software/

java ncso发送电邮

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值