0

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

4

2 回答 2

0

为此使用此代码,

 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();
    }
    }
于 2013-10-23T12:56:23.120 回答
0

只需在您的 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>
于 2012-05-30T13:39:01.013 回答