我用文本框和一個提交我的.aspx頁面上的按鈕,我想以電子郵件的按鈕上點擊所有這些文本框的數據,所以請告訴我的解決方案...如何從.aspx頁面發送電子郵件?
-9
A
回答
3
按鈕點擊事件調用此函數
public bool SendOnlyToEmail(string sToMailAddr, string sSubject, string sMessage,
string sFromMailAddr)
{
try
{
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
if (string.IsNullOrEmpty(sFromMailAddr))
{
// fetching from address from web config key
msg.From = new System.Net.Mail.MailAddress(System.Configuration.ConfigurationManager.AppSettings["MailFrom"]);
}
else
{
msg.From = new System.Net.Mail.MailAddress(sFromMailAddr);
}
foreach (string address in sToMailAddr)
{
if (address.Length > 0)
{
msg.To.Add(address);
}
}
msg.Subject = sSubject;
msg.Body = sMessage;
msg.IsBodyHtml = true;
//fetching smtp address from web config key
System.Net.Mail.SmtpClient objSMTPClient = new System.Net.Mail.SmtpClient(System.Configuration.ConfigurationManager.AppSettings["MailServer"]);
//SmtpMail.SmtpServer = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["MailServer"]);
if (sToMailAddr.Length > 0)
{
objSMTPClient.Send(msg);
return true;
}
else
{
return false;
}
}
catch (Exception objException)
{
ErrorLog.InsertException(objException);
return false;
}
}
2
您可以使用SmtpClient
類。
2
有沒有代碼唯一的方法來解決這個問題;你依賴於有一個SMTP服務器來發送你的郵件。最佳案例場景:您已經在服務器上設置了一個默認端口。在這種情況下,你需要的是這樣的:
SmtpClient client = new SmtpClient("localhost");
client.Send(new MailMessage("[email protected]", "[email protected]"));
如果做不到這一點,你可以看看建立一個免費的SMTP帳戶,或(絕對必要無論如何,如果你在發出大量電子郵件規劃),得到一個與Amazon SES等電子郵件服務提供商交涉。
1
您可以使用下面的代碼來發送電子郵件:
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
MailAddress fromAddress = new MailAddress("senderEmail");
message.From = fromAddress;
message.Subject = "your subject";
message.Body = txtBox.Text;//Here put the textbox text
message.To.Add("to");
smtpClient.Send(message);//returns the boolean value ie. success:true
1
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
//create the mail message
MailMessage mail = new MailMessage();
//set the addresses
mail.From = new MailAddress("[email protected]");
mail.To.Add("[email protected]");
//set the content
mail.Subject = "This is an email";
mail.Body = "this is the body content of the email.";
//send the message
SmtpClient smtp = new SmtpClient();
smtp.Send(mail);
}
</script>
相關問題
- 1. 從aspx頁面發送電子郵件
- 2. aspx:發送電子郵件
- 3. 從ASP.NET頁面發送電子郵件
- 4. 創建一個單獨的aspx頁面發送電子郵件
- 5. asp.net發送aspx頁面的部分電子郵件
- 6. 用gridviews發送aspx頁面作爲電子郵件
- 7. 如何從Wordpress頁面發送電子郵件附件?
- 8. 頁面發送電子郵件
- 9. 通過電子郵件發送頁面
- 10. 如何從javascript發送電子郵件?
- 11. 如何從C發送電子郵件
- 12. 如何從Node.js發送電子郵件?
- 13. 如何從ASP.Net發送電子郵件
- 14. 如何從PHPmyAdmin發送電子郵件?
- 15. 如何從broadcastreceiver發送電子郵件?
- 16. 發送電子郵件從
- 17. 如何使用c#aspx發送電子郵件的MIME數據
- 18. 如何在發送電子郵件後防止頁面刷新?
- 19. 如何通過HTML發送電子郵件頁面
- 20. 如何在頁面重定向之前發送電子郵件
- 21. 如何在訪問頁面時發送電子郵件通知?
- 22. 如何使用drupal_mail頁面功能發送電子郵件 - front.tpl
- 23. 是否可以在電子郵件正文中發送aspx頁面?
- 24. 從ASP經典頁面發送電子郵件與憑據
- 25. 電子郵件從網站頁面發送 - Odoo V9社區
- 26. 無法從PHP頁面發送電子郵件
- 27. Ruby on Rails:從顯示頁面發送電子郵件
- 28. 不能通過電子郵件發送到Facebook頁面從PHP
- 29. 從asp經典頁面發送電子郵件
- 30. 發送電子郵件操作不發送電子郵件