简体   繁体   English

webmail.send电子邮件地址前后的逗号

[英]Comma before and after an email address of webmail.send

I am trying to implement smtp on asp.net web pages (razor page) and sql server 2017. The email notification was supposed to send after submitting a form using an email address stored in sql database but each I click submit, the notification fails to send. 我正在尝试在asp.net网页(剃刀页面)和sql server 2017上实施smtp。应该使用存储在sql数据库中的电子邮件地址提交表单后发送电子邮件通知,但是每次单击提交后,通知都无法执行发送。 So, I tried debugging it by adding a breakpoint and stepped into the smtp initiallizer. 因此,我尝试通过添加断点来调试它,并进入smtp初始化程序。 I found out that there is a comma (,) before and after the email address. 我发现电子邮件地址前后有一个逗号(,)。 When I remove the two commas, the notification sends but I don't know how to permanently remove it without having to do it by putting a breakpoint so that my application can run. 当我删除两个逗号时,将发送通知,但我不知道如何永久删除它,而不必通过放置断点来使我的应用程序可以运行。

Attached is the screenshoot. 附件为屏幕截图。

Thank you so much for your help. 非常感谢你的帮助。

// Initialize WebMail helper
 WebMail.SmtpServer = "smtp.office365.com";
 WebMail.SmtpPort = 25;
 WebMail.UserName = "help@me.please";
 WebMail.Password = "Help123";
 WebMail.From = "help@me.please";
 WebMail.EnableSsl = true;



 WebMail.Send(to: Email,
 subject: "Visitor Alert",
 body: " Hello: <br/> " + "Hope you're having a good time!);

在此处输入图片说明

It seems there are invalid entries in your database, you should validate that because everybody might be trying to put in corrupted data. 您的数据库中似乎有无效的条目,您应该进行验证,因为每个人都可能试图放入损坏的数据。 Another possibility is that some parsing went wrong which resulted in corrupted data. 另一种可能性是某些解析出错,导致数据损坏。

Anyhow, to fix this specific case, you can trim the email address: 无论如何,要解决此特定情况,您可以调整电子邮件地址:

WebMail.Send(to: email.Trim(','),
             subject: "Visitor Alert",
             body: " Hello: <br/> " + "Hope you're having a good time!); 

Nevertheless, this is just fixing a symptom for another underlying problem. 尽管如此,这只是解决了另一个潜在问题的症状。

What would work is the following: 可行的方法如下:

// Initialize WebMail helper
WebMail.SmtpServer = "smtp.office365.com";
WebMail.SmtpPort = 25;
WebMail.UserName = "help@me.please";
WebMail.Password = "Help123";
WebMail.From = "help@me.please";
WebMail.EnableSsl = true;



WebMail.Send(to: Email.Replace(',',''),
subject: "Visitor Alert",
body: " Hello: <br/> " + "Hope you're having a good time!)";

I added a 我加了

.Replace(',','')

which removes the unwanted commas from any email you have 从您收到的任何电子邮件中删除不需要的逗号

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM