本文介绍了该消息在当前上下文中不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 消息 .ISBodyHtml = true; SmtpClient客户端=新的SmtpClient(smpt.gmail.com,587); 客户端.EnableSsl = true; client.Credentials = new System.Net.NetworkCredential([email protected],prudhviraj); client.Send(消息); 来自上面的代码显示的消息没有存在于当前背景下 我尝试过: 使用系统; 使用System.Collections.Generic; 使用System.Linq; 使用System.Web; 使用System.Web.UI; 使用System.Web.UI.WebControls; 使用System.Net.Mail; public partial class _Default:System.Web.UI.Page { protected void Page_Load(object sender,EventArgs e) { } 受保护void Button1_Click(object sender,EventArgs e) { try { MailMessage mail = new MailMessage( To.Text,From.Text,Subject.Text,Body.Text); message.ISBodyHtml = true; SmtpClient client = new SmtpClient(smpt.gmail。 com,587); client.EnableSsl = true; client.Credentials = new System.Net.NetworkCredential([email protected],prudhviraj ); client.Send(message); Status.Text =邮件发送成功; } catch(Exception ex) { Status.Text = ex.StackTrace; } Status.Text =点击发送; } }message.ISBodyHtml = true; SmtpClient client = new SmtpClient("smpt.gmail.com", 587); client.EnableSsl = true; client.Credentials = new System.Net.NetworkCredential("[email protected]", "prudhviraj"); client.Send(message);from the above code its showing message does not exist in the current contextWhat I have tried:using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Net.Mail;public partial class _Default : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { try { MailMessage mail = new MailMessage(To.Text, From.Text, Subject.Text, Body.Text); message.ISBodyHtml = true; SmtpClient client = new SmtpClient("smpt.gmail.com", 587); client.EnableSsl = true; client.Credentials = new System.Net.NetworkCredential("[email protected]", "prudhviraj"); client.Send(message); Status.Text = "mail sent sucessfully"; } catch(Exception ex) { Status.Text = ex.StackTrace; } Status.Text = "Send is clicked"; }}推荐答案你申报了av名称为mail,而不是message。这是一个非常基本的事情,你是否尝试自己解决它? 另外,我建议你从你的问题中删除你的电子邮件凭证。You declared a variable with name "mail", not "message". This is a really very basic thing, did you even try to solve it by yourself?Also, I recommend you to remove your email credentials from your question.尝试:Try:MailMessage message = new MailMessage(To.Text, From.Text, Subject.Text, Body.Text);message.ISBodyHtml = true;SmtpClient client = new SmtpClient("smpt.gmail.com", 587);client.EnableSsl = true;client.Credentials = new System.Net.NetworkCredential("[email protected]", "prudhviraj");client.Send(message);Status.Text = "mail sent sucessfully"; 最好的问候 Espen HarlinnBest regardsEspen Harlinn它应该是It should beclient.Send(mail); 因为您的邮件消息对象是邮件而不是邮件。because your mail message object is mail not message. 这篇关于该消息在当前上下文中不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-23 21:45