如何在SQL Server中保存数据并发送电子邮件通知。

编程入门 行业动态 更新时间:2024-10-09 12:32:42
本文介绍了如何在SQL Server中保存数据并发送电子邮件通知。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我真的很难让这一点正确。我希望我的按钮能够将在webform上输入的数据保存到数据库中,同样的按钮也应该发送通知邮件。 这是我所得到的基本示例:

Hi, I'm really struggling to get this one right. I want my button to SAVE the data entered on a webform into the database AND that same button should send a notification mail as well. This is the basic example of what I've got:

private void button() { Save(); SendEmail(); } private void SendEmail() { //code here; } private void Save() { //code here; }

好​​的,现在是第一部分完美无缺,这就是SAVE方法()。 SendEMail部分是苦苦挣扎的开始。 首先关闭。选择下拉列表中的名称(此名称与该人的电子邮件地址对应)。然后其余部分填写。 数据库示例:

Okay, now the first part works perfectly fine, and that's the SAVE method(). The SendEMail part is where the struggling starts. First off. A name in a drop down list is selected (this name corresponds with that person's email address). then the rest is filled in. Example of a database:

ID Name Email 0 aaa aaa@a

因此,一旦选择了下拉列表,就应该选择电子邮件地址。这部分也适合我。 现在,当我按下提交按钮保存数据并将通知发送给所选人时,它会给我一个SMTP例外。这是我的SendEmail()代码:

So once the dropdownlist is selected, is should select the email address. This part works fine for me too. Now, when I press on the submit button which Saves data and sends the notification to the person selected, it gives me an SMTP Exception. This is my SendEmail() code:

MailMessage message = new MailMessage(); SmtpClient smtpClient = new SmtpClient(); string msg = string.Empty; try { MailAddress fromAddress = new MailAddress(from); message.From = fromAddress; message.Subject = subject; message.IsBodyHtml = true; message.Body = body; smtpClient.Host = "mail.server"; smtpClient.Port = 25; smtpClient.UseDefaultCredentials = true; smtpClient.Credentials = new System.Net.NetworkCredential("info@server", "password"); smtpClient.Send(message); msg = "Successful";

我很确定某些设置或某些东西仍然不对,因为我尝试了多行不同的代码确保电子邮件正常工作,但仍然会遇到异常。有时会给出超时时间。 是的,有人可以帮助我。

I am pretty sure some setting or something is still not right because I've tried multiple lines of different code to make sure the emails are working, but still get that exception. Sometimes it gives a Time Out Exception. Yeah, so can anybody help me please.

推荐答案

通过这个 - 在数据库中插入记录后发送电子邮件 [ ^ ]

可能性: 1.我可能是SSL的案例。 您可以尝试: Hi, Possibilities : 1. I may be a case of SSL. You could try : smtpClient.EnableSSL=true;

2.检查端口和IP是否可从客户端PC /服务器访问

2. Check port and IP is accessible from the client pc /server

更多推荐

如何在SQL Server中保存数据并发送电子邮件通知。

本文发布于:2023-10-12 16:16:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1485247.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发送电子邮件   通知   数据   如何在   Server

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!