我想将邮件中的电子邮件ID发送到文本框中输入的电子邮件 [英] I want to send email id from my mail to the email entered in textbox

查看:101
本文介绍了我想将邮件中的电子邮件ID发送到文本框中输入的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我试图运行的代码,但它给出了错误



  public   void  sendmail()
{
string to = TextBox2 。文本;
string 来自 = xyz@gmail.com;
MailMessage message = new MailMessage( from ,to);

message.Subject = 这是我的主题;

message.Body = 这是内容;

SmtpClient client = new SmtpClient();

client.Send(message);
}





它不会接受来自textbox2.text

解决方案

 string to = TextBox2.Text; 





应该是



 string to = tb2.Text; 





[请接受/上传 - 投票答案或解决方案,为你鼓励参与]


当然,它不会,但它会像这样工作

  public   void  sendmail( string  toAddr )
{
string to = toAddr;
string 来自 = xyz@gmail.com;
MailMessage message = new MailMessage( from ,to);

message.Subject = 这是我的主题;

message.Body = 这是内容;

SmtpClient client = new SmtpClient();

client.Send(message);
}

protected void sendBtn_Click( object sender,EventArgs e)
{
sendMail(TextBox2.Text);
}





参数必须作为参数传递给函数 - 函数/方法的基本规则



-KR


试试这个.. :)



 尝试 
{
string to = TextBox2.Text;
string 来自 = xyz@gmail.com;


MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient( smtp .gmail.com);

mail.From = new MailAddress( me@mydomain.com);
mail.To.Add(to);
mail.Subject = 这是我的主题;
mail.Body = 这是内容;
附件附件= new 附件(文件名);
mail.Attachments.Add(附件);

SmtpServer.Port = 25 ;
SmtpServer.Credentials = new System.Net.NetworkCredential( 用户名 password);
SmtpServer.EnableSsl = true ;

SmtpServer.Send(mail);
}


this is the code i am trying to run but it gives error

public  void sendmail()
    {
        string to = TextBox2.Text;
        string from = "xyz@gmail.com";
        MailMessage message = new MailMessage(from,to);
        
        message.Subject = "This is my subject";

        message.Body = "This is the content";

        SmtpClient client = new SmtpClient();
               
        client.Send(message);
    }



it wont accept the value from textbox2.text

解决方案

string to = TextBox2.Text;



Should be

string to = tb2.Text;



[Please accept/up-vote answers or solutions that work for you to encourage participation]


Of course, it won't but It would work like this

public  void sendmail(string toAddr)
{
    string to = toAddr;
    string from = "xyz@gmail.com";
    MailMessage message = new MailMessage(from,to);
    
    message.Subject = "This is my subject";

    message.Body = "This is the content";

    SmtpClient client = new SmtpClient();
           
    client.Send(message);
}

protected void sendBtn_Click(object sender, EventArgs e)
{
    sendMail(TextBox2.Text);
}



Parameters must be passed as an arguments to the function - basic rule of function/method.

-KR


try this.. :)

try
            {
                string to = TextBox2.Text;
                string from = "xyz@gmail.com";


                MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
 
                mail.From = new MailAddress("me@mydomain.com");
                mail.To.Add(to);
                mail.Subject = "This is my subject";
                mail.Body = "This is the content";
                Attachment attachment = new Attachment(filename);
                mail.Attachments.Add(attachment);
 
                SmtpServer.Port = 25;
                SmtpServer.Credentials = new System.Net.NetworkCredential("Username", "password");
                SmtpServer.EnableSsl = true;
 
                SmtpServer.Send(mail);
            }


这篇关于我想将邮件中的电子邮件ID发送到文本框中输入的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆