Tag: 电子邮件

无法从SQL Server发送电子邮件

我正在尝试从SQL Server发送电子邮件到触发器。 我按照本博客的指导进行了表演。 每当我尝试作为电子邮件时,我都会收到错误消息。 EXEC msdb.dbo.sysmail_add_account_sp @account_name = ‘ChandreshTestAccount’ , @description = ‘Sending email from test account’ , @email_address = ‘chandresh.cmk@gmail.com’ , @display_name = ‘No-Reply’ , @replyto_address = ‘chandresh.cmk@gmail.com’ , @mailserver_name = ‘smtp.gmail.com’ , @port = 25 , @username = ‘chandresh.cmk@gmail.com’ , @password = ‘xxxxxxx’ Go 错误:由于邮件服务器故障,无法将邮件发送给收件人。 (使用帐户6发送邮件(2017-02-02T14:24:46)。exception消息:无法连接到邮件服务器。(连接尝试失败,因为连接方在一段时间后没有正确响应,或建立连接失败,因为已连接的主机无法响应74.125.68.109:25)。) 然后我试图更改端口号587并得到以下错误。 由于邮件服务器故障,无法将邮件发送给收件人。 (使用帐户5发送邮件(2017-02-02T14:28:22)。例外消息:无法向邮件服务器发送邮件。(SMTP服务器需要安全连接或客户端未经过身份validation。服务器响应为:5.7。 0必须首先发出STARTTLS命令.n8sm30283000pgc.16 – gsmtp)。) 然后我再次尝试更改端口号465并得到以下错误 […]

提取gmail,yahoomail和AOL联系人的c#库

是否有任何好的c#库提取gmail,yahoomail和AOL联系人? 任何建议…… 我查看了Opencontacts.net ,我在我的asp.net Web应用程序中使用了opencontacts.dll,但我无法使其工作…它显示错误Could not load file or assembly ‘Utilities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’ or one of its dependencies. The system cannot find the file specified. Could not load file or assembly ‘Utilities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’ or one of its dependencies. The system cannot find the file specified. …. 我这样做了, OpenContactsNet.GmailExtract gm = new OpenContactsNet.GmailExtract(); […]

在ASP.NET中以编程方式发送带附件的邮件

我基于ASP.NET中的GridView动态生成许多不同类型的文件 – Excel电子表格和HTML文件。 我这样做是使用此代码(这仅适用于Excel电子表格): Response.Clear(); Response.AddHeader(“content-disposition”, “attachment;filename=InvoiceSummary” + Request.QueryString[“id”] + “.xls”); Response.Charset = “”; Response.ContentType = “application/vnd.xls”; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); contents.RenderControl(htmlWrite); //GridView1.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End(); 我想向用户提供选项,通过电子邮件将生成的文件作为附件发送给他们指定的电子邮件地址,或者将其与数据库中的帐户相关联。 但我不希望用户必须保存文件,然后将其附加到表单中 – 我想自动附加生成的文件。 这有可能吗,它有多容易? 当然,我将使用System.Net.Mail类发送邮件……如果可能的话!

C#发送HTML和Text电子邮件 – 最优雅?

发送HTML和Text电子邮件是最佳做法吗? 如果我只发送HTML有什么危险? 我正在考虑下面这样的事情 http://johnnycoder.com/blog/2009/04/15/net-mailmessage-linkedresources-alternateviews-and-exceptions/ try { // Assign a sender, recipient and subject to new mail message MailAddress sender = new MailAddress(“sender@johnnycoder.com”, “Sender”); MailAddress recipient = new MailAddress(“recipient@johnnycoder.com”, “Recipient”); MailMessage m = new MailMessage(sender, recipient); m.Subject = “Test Message”; // Define the plain text alternate view and add to message string plainTextBody = “You must […]

ASP.NET MVC电子邮件

他们是使用ASP.NET MVC View生成电子邮件模板的解决方案,而无需跳过篮球。 让我详细说明跳过篮球。 var fakeContext = new HttpContext(HttpContext.Current.Request, fakeResponse); var oldContext = HttpContext.Current; HttpContext.Current = fakeContext; var html = new HtmlHelper(new ViewContext(fakeControllerContext, new FakeView(), viewDataDictionary, new TempDataDictionary()), new ViewPage()); html.RenderPartial(viewName, viewData, viewDataDictionary); HttpContext.Current = oldContext; 上面的代码使用当前的HttpContext伪造一个新的Context并使用RenderPartial渲染页面,我们不应该这样做。 使用ControllerContext和.Render的另一个非常详细的解决方案:( IEmailTemplateService,Headers / Postback WorkAround ),但是用更多的代码做同样的事情。 另一方面,我正在寻找能够呈现View而不必POST / GET的东西,并生成一个简单的字符串,我可以通过我的电子邮件代码发送。 不会发生错误的事情,例如两次发布标题或伪造一些数据。 EX: //code which does not fire Render, RenderPartial… […]

查找exception的确切原因 – System.Net.Sockets.SocketException

我尝试使用下面给出的代码将邮件发送到SMTP邮件服务器。 但是,我收到一个错误 – Error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.Net.Mail.SmtpException: Failure sending mail. —> System.Net.WebException: Unable to connect to the remote server —> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host […]

使用smtp SendAsync发送邮件

这是当我需要发送电子邮件给我错误。 但是从那以后的错误是这样的: 此时无法启动异步操作。 异步操作只能在异步处理程序或模块中启动,或者在页面生命周期中的某些事件中启动。 如果在执行页面时发生此exception,请确保将页面标记为。 此exception还可能表示尝试调用“异步void”方法,该方法通常在ASP.NET请求处理中不受支持。 相反,异步方法应该返回一个Task,调用者应该等待它。 我从MVC开始积累并使用类来跟踪页面的区域。 我使用SendAsync的原因正是它发送电子邮件等更快一些。 仅当我尝试向用户发送电子邮件时才会出现此错误。 public static void NewPassword(string mail, string name, string password) { MailDefinition oMailDefinition = new MailDefinition(); oMailDefinition.BodyFileName = “~/MailList/emailskabelon/NewPassword.html”; oMailDefinition.From = FromMail; Dictionary oReplacements = new Dictionary(); oReplacements.Add(“<>”, name); oReplacements.Add(“<>”, password); System.Net.Mail.MailMessage oMailMessage = oMailDefinition.CreateMailMessage(mail, oReplacements, new LiteralControl()); oMailMessage.Subject = NewpasswordTitle + WebsiteName; oMailMessage.IsBodyHtml = true; […]

是否可以重置ServicePointManager?

我试图遵循类似于System.Net.Mail.SMTPClient如何进行本地IP绑定的代码我在具有多个IP地址的计算机上使用Windows 7和.Net 4.0。 我定义了BindIPEndPointDelegate private static IPEndPoint BindIPEndPointCallback(ServicePoint servicePoint, IPEndPoint remoteEndPoint, int retryCount) { string IPAddr = //some logic to return a different IP each time return new IPEndPoint(IPAddr, 0); } 然后我使用发送电子邮件 SmtpClient client = new SmtpClient(); client.Host = SMTP_SERVER; //IP Address as string client.Port = 25; client.EnableSsl = false; client.ServicePoint.BindIPEndPointDelegate = new System.Net.BindIPEndPoint(BindIPEndPointCallback); client.ServicePoint.ConnectionLeaseTimeout […]

WCF服务无法通过MailDefinition发送邮件

// stuff…… return SendCreationMail(Membership.GetUser((Guid)request.UserEntityId), request, new Control()); } private const string TemplateRoot = “~/app_shared/templates/mail/”; private const string ServerRoot = TemplateRoot + “server/”; public static bool SendCreationMail(MembershipUser user, IServerAccountRequest request, Control owner) { var definition = new MailDefinition { BodyFileName = string.Concat(ServerRoot, “creation.htm”), IsBodyHtml = true }; var subject = “New {0} account created!”.FormatWith(request.ServerApplicationContract.Id); var data […]

向MailMessage添加附件时流关闭错误

我使用以下代码将文件附加到电子邮件中。 msg = new MailMessage(); using (strMem = new MemoryStream((byte[])attDr[“filedata”])) { using (strWriter = new StreamWriter(strMem)) { strWriter.Flush(); strMem.Position = 0; using (attachment = new Attachment(strMem, attDr[“filename”].ToString())) { msg.Attachments.Add(attachment); } } } … … msg.Send(); //Error: System.ObjectDisposedException: Cannot access a closed Stream. 错误消息是://错误:System.ObjectDisposedException:无法访问已关闭的Stream 我猜测“USING”语句在退出块时关闭流。 但为什么“Attacments.Add()”没有制作自己的流副本?