如何在不使用本地主机的电子邮件ID和密码等邮件凭证的情况下发送邮件?
答案 0 :(得分:0)
只需在c:/驱动器上创建一个名为“maildrop”的文件夹,并在Web.config文件中使用以下内容:
<mailSettings>
<smtp deliveryMethod='SpecifiedPickupDirectory'>
<specifiedPickupDirectory pickupDirectoryLocation="c:\maildrop" />
</smtp>
</mailSettings>
更多信息:
对于没有凭据的外部交付:
<mailSettings>
<smtp from="info@mysite.com">
<network host="smtp.myhost.com"/>
</smtp>
</mailsettings>
答案 1 :(得分: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();
}
}