- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个使用 ASP.net 和 C# 的 Web 应用程序,一步之内它需要从用户到向带有附件的人发送电子邮件。我的问题是当用户发送电子邮件时我不想把他们的每次用户发送密码。我想发送一封没有发件人密码的电子邮件。有什么方法可以使用 SMTP 做到这一点?这是我的代码示例“并非全部”。当我输入密码时,代码可以正常工作,但没有它,它不起作用,我需要一种无需输入密码即可发送电子邮件的方法,但是同时使用smtp协议(protocol)。
private void button1_Click(object sender, EventArgs e)
{
string smtpAddress = "smtp.office365.com";
int portNumber = 587;
bool enableSSL = true;
string emailFrom = "my email";
string password = "******";
string emailTo = "receiver mail";
string subject = "Hello";
string body = "Hello, I'm just writing this to say Hi!";
using (MailMessage mail = new MailMessage())
{
mail.From = new MailAddress(emailFrom);
mail.To.Add(emailTo);
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = true;
// Can set to false, if you are sending pure text.
// mail.Attachments.Add(new Attachment("C:\\SomeFile.txt"));
// mail.Attachments.Add(new Attachment("C:\\SomeZip.zip"));
using (SmtpClient smtp = new SmtpClient(smtpAddress,portNumber))
{
smtp.UseDefaultCredentials = true;
smtp.Credentials = new NetworkCredential(emailFrom, password);
smtp.EnableSsl = enableSSL;
smtp.Send(mail);
}
MessageBox.Show("message sent");
}
}
最佳答案
我相信这可以很容易地完成,但有一些限制。
看看 MSDN article on configuring SMTP in your config file .
如果您的 SMTP 服务器允许,您的电子邮件对象的发件人地址可能不需要与用于连接到 SMTP 服务器的凭据相同。
因此,设置您的电子邮件对象的发件人地址:
mail.From = new MailAddress(emailFrom);
但是,请使用以下两种方式之一配置您的 smtp 连接:
然后,做这样的事情:
using (SmtpClient smtp = new SmtpClient())
{
smtp.Send(mail);
}
让配置文件为您设置 SMTP。这也很棒,因为如果您切换服务器,则无需更改任何代码。
请记住要小心配置文件中的任何敏感设置! (又名,不要将它们 checkin 公共(public) github 存储库)
关于c# - 在 C# 中使用无密码的 SMTP 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42845060/
大家好,我是 php 和 html 新手,面临问题:SMTP 错误:无法连接到 SMTP 主机。邮件程序错误:SMTP 错误:无法连接到 SMTP 主机。但在本地 xampp 中工作正常,在服务器中出
我希望这个问题不是完全偏离主题。 我一直想知道 SMTP 电子邮件验证。有很多服务(例如 Kickbox.io、Email-Validator.net 等)似乎可以处理 SMTP 验证,而不会阻止其
我正在尝试使用 phpMailer 通过电子邮件向用户发送确认消息。我的代码是这样的: IsSMTP(); // set mailer to use SMTP $mail->Host = "ssl:/
我已经在我的本地机器(Windows 7)上安装了 bugzilla 并且它运行良好。但是当我尝试创建一个新帐户时,它说 There was an error sending mail from it
我有一个将发送大量输出的程序。我只是想知道最大电子邮件附件大小是多少?根据RFC 1870邮件服务器可以拒绝邮件,因为它们太大了,但是使用 SMTP/MIME 时有最大大小吗?我在这方面找不到任何东西
假设我有一个网站,其某些功能需要电子邮件验证(例如用户注册)。当然,我会使用正则表达式验证电子邮件,但曾几何时,我在其他人的代码中看到了 SMTP 验证。 SMTP 验证有哪些优点和缺点? 我可以假设
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 2年前关闭。 Improve thi
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
我正在尝试使用 Vala 和 GLib + GIO 实现一个简单的 SMTP 服务器。 到目前为止,纯文本通信没有问题,但当涉及使用 STARTTLS 的 TLS 时,事情会变得更加困难。 这是我到目
我使用 go 的 net/smtp 发送电子邮件,它对某些电子邮件工作正常但对其他电子邮件无效。我收到 554 5.5.1 Error: no valid recipients 但我很确定我提供了正确
我需要帮助 这是我的代码: require 'PHPMailerAutoload.php'; $mail = new PHPMailer; $mail->isSMTP(); $mail->Host =
我的 joomla 联系表 gmail SMTP 设置不起作用。请参阅下面提交联系表时显示的消息。应该是什么原因?extension=php_openssl.dll 也启用了.. 错误信息-: SMT
我正在尝试使用 Amazon 的 SES/SMTP 发送电子邮件,但出现以下错误: javax.mail.MessagingException:无法连接到 SMTP 主机:email-smtp.us-
在我的Mac终端上,我试图通过telnet将smtp.gmail.com转换为port 587。 在Google Apps(设置为管理Dreamhost域)上,我已配置了中继,如下所示: "Allow
理论上,Request For Comments (RFC) 集包含开发人员构建 SMTP 客户端需要知道的一切。然而,要知道哪些 RFC 需要考虑,哪些可以忽略并不总是那么容易。 有没有人有 RFC
MT 支持 SMTP SendMail,还是我坚持使用 MFMailComposeViewController?现在,我可以使用它(MFMailComposeViewController),但是当我添
很难说出这里问的是什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或言辞激烈,无法以目前的形式合理回答。如需帮助澄清此问题以便可以重新打开,visit the help center . 10年前关
我正在尝试通过 BizTalk SMTP 发送端口发送消息。具体来说,我正在通过编排的“稍后指定”端口发送消息。我的目标是使用我选择的附件文件名将消息正文附加到已发送的电子邮件。 但是,无论我尝试什么
我正在编写一个通过有效的 GMail 用户 ID 和密码发送邮件的应用程序。 我只是想在 Windows XP 命令行上模拟 SMTP 连接,当我在 465 端口 telnet smtp.gmail.
关于从应用程序通过 GMails SMTP 服务器发送的电子邮件被标记为垃圾邮件的问题已经有很多讨论。 阅读其他帖子我无法弄清楚我的问题。我的电子邮件最终仍然是 SPF 中性的。 在我的 *(捕获所有
我是一名优秀的程序员,十分优秀!