I want to send an email to a user after they submit a form in my C# application. Their email address is stored in the database and I want to create a stored procedure that will pick their email address according to their man no.
This is my working code so far but it only applies to already listed email addresses.
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
SmtpClient SmtpServer = new SmtpClient("smtp.office365.com", 25);
SmtpServer.EnableSsl = true;
SmtpServer.Timeout = 10000000;
SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Credentials = new System.Net.NetworkCredential(email, password, domain);
MailMessage mail = new MailMessage();
mail.From = new MailAddress(email);
mail.To.Add(""); **//Want this to come calling a stored procedure**
mail.Subject = "MAIL TEST";
mail.Body = "Mail code working";
mail.IsBodyHtml = true;
SmtpServer.Send(mail);
SmtpServer.Dispose();
SmtpServer.SendCompleted += (s, x) => {
SmtpServer.Dispose();
mail.Dispose();
};
WebMessageBox.Show("Mail sent");
1条答案
按热度按时间rbpvctlc1#
You would need to create a C# part and a tSQL part to make this work.
C#
SQL
And then modify your code as such:
This is all pseudo code. You'll have to modify the Store Procedure and C# function to match your parameters, store procedure name, and other unknowns which you haven't shown us. You might also want to add some error handling using
try {} catch {}
blocks.