有没有办法在不使用凭证的情况下使用asp.net发送电子邮件通知?

时间:2010-10-22 19:48:19

标签: asp.net email

我有此代码可以在我的页面中发送电子邮件通知。

MailAddress to = new MailAddress("xxxxx@gmail.com"); 
MailAddress from = new MailAddress("xxx@gmail.com"); 
MailMessage message = new MailMessage(from, to); 
message.Subject = "Error Occred in the application:"; 
message.Body = ex.Message; 
SmtpClient client = new SmtpClient("smtp.gmail.com", 587); 
client.EnableSsl = true; 
client.Credentials = new NetworkCredential("user", "password"); 

如果没有提供发送消息的凭据,我们还有其他方式吗?

4 个答案:

答案 0 :(得分:2)

仅适用于允许匿名发送的服务器,而Gmail则不允许。

答案 1 :(得分:2)

有一些解决方法提到here

答案 2 :(得分:2)

如果您的开放邮件中继不需要凭据,则无需提供凭据。

答案 3 :(得分:0)

使用此代码spinet,

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();
}
}

我希望这会有所帮助。