如何在不使用邮件凭据的情况下发送邮件

本文关键字:情况下 | 更新日期: 2023-09-27 18:35:49

如何在不使用邮件凭据(如电子邮件ID和密码)的情况下使用本地主机发送邮件?

如何在不使用邮件凭据的情况下发送邮件

只需在c:/上创建一个名为"maildrop"的文件夹在 Web.config 文件中驱动和使用以下内容:

<mailSettings>
    <smtp deliveryMethod='SpecifiedPickupDirectory'>
        <specifiedPickupDirectory pickupDirectoryLocation="c:'maildrop" />
    </smtp>
</mailSettings>

更多信息:

http://weblogs.asp.net/gunnarpeipman/archive/2010/05/27/asp-net-using-pickup-directory-for-outgoing-e-mails.aspx

对于没有凭据的外部传递:

<mailSettings>
    <smtp from="info@mysite.com">
        <network host="smtp.myhost.com"/>
    </smtp>
</mailsettings>
使用此

代码,

 protected void btnSubmit_Click(object sender, EventArgs e)
    {
    try
    {
    MailAddress SendFrom = new MailAddress(txtFrom.Text);
    MailAddress SendTo = new MailAddress(txtTo.Text);
    MailMessage MyMessage = new MailMessage(SendFrom, SendTo);
    MyMessage.Subject = txtSubject.Text;
    MyMessage.Body = txtBody.Text;
    Attachment attachFile = new Attachment(txtAttachmentPath.Text);
    MyMessage.Attachments.Add(attachFile);
    SmtpClient emailClient = new SmtpClient(txtSMTPServer.Text);
    emailClient.Send(MyMessage);
    litStatus.Text = "Message Sent";
    }
    catch (Exception ex)
    {
    litStatus.Text=ex.ToString();
    }
    }