Click here to Skip to main content
15,919,358 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
using System;
using System.Net;
using System.Net.Mail;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MailSend
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void groupBox2_Enter(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void textBox6_TextChanged(object sender, EventArgs e)
        {

        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void textBox5_TextChanged(object sender, EventArgs e)
        {

        }


        private void btnBrowse_Click(object sender, EventArgs e)
        {
            OpenFileDialog obj = new OpenFileDialog();
            DialogResult res = obj.ShowDialog();
            if (res == DialogResult.OK)
            {
                string fpath;
                fpath = obj.FileName;
                txtAttachments.Text = fpath;
            }
        }

               private void button1_Click(object sender, EventArgs e)
        {
            SmtpClient obj = new SmtpClient();
            NetworkCredential n = new NetworkCredential(txtFrom.Text, "Jeetendra", System.Text.Encoding.UTF8);
            msg.From = m;
            msg.To.Add(txtTo.Text);
            msg.Subject = txtSub.Text;
            msg.Body = txtBody.Text;
            msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
            Attachment a = new Attachment(txtAttachments.Text);
            msg.Attachments.Add(a);
            obj.Send(msg);
            MessageBox.Show("Mail Sent Successfully.....!!!!");
        
        }

        
    }
}


I am getting following errors

following errors ar coming... Error 1 The best overloaded method match for 'System.Net.NetworkCredential.NetworkCredential(string, string, string)' has some invalid arguments D:\BE630\MailSend\MailSend\Form1.cs 67 35 MailSend 
Error 2 Argument '3': cannot convert from 'System.Text.Encoding' to 'string' D:\BE630\MailSend\MailSend\Form1.cs 67 84 MailSend 
Error 3 The name 'msg' does not exist in the current context D:\BE630\MailSend\MailSend\Form1.cs 68 13 MailSend 
Error 4 The name 'm' does not exist in the current context D:\BE630\MailSend\MailSend\Form1.cs 68 24 MailSend 
Error 5 The name 'msg' does not exist in the current context D:\BE630\MailSend\MailSend\Form1.cs 69 13 MailSend 
Error 6 The name 'msg' does not exist in the current context D:\BE630\MailSend\MailSend\Form1.cs 70 13 MailSend 
Error 7 The name 'msg' does not exist in the current context D:\BE630\MailSend\MailSend\Form1.cs 71 13 MailSend 
Error 8 The name 'msg' does not exist in the current context D:\BE630\MailSend\MailSend\Form1.cs 72 13 MailSend 
Error 9 The name 'msg' does not exist in the current context D:\BE630\MailSend\MailSend\Form1.cs 74 13 MailSend 
Error 10 The name 'msg' does not exist in the current context D:\BE630\MailSend\MailSend\Form1.cs 75 22 MailSend
Posted
Updated 7-Mar-14 21:21pm
v3
Comments
[no name] 8-Mar-14 3:12am    
What to correct..??What is the problem you are facing..??
Tjeetu 8-Mar-14 3:18am    
following errors ar coming...
Error 1 The best overloaded method match for 'System.Net.NetworkCredential.NetworkCredential(string, string, string)' has some invalid arguments D:\BE630\MailSend\MailSend\Form1.cs 67 35 MailSend
Error 2 Argument '3': cannot convert from 'System.Text.Encoding' to 'string' D:\BE630\MailSend\MailSend\Form1.cs 67 84 MailSend
Error 3 The name 'msg' does not exist in the current context D:\BE630\MailSend\MailSend\Form1.cs 68 13 MailSend
Error 4 The name 'm' does not exist in the current context D:\BE630\MailSend\MailSend\Form1.cs 68 24 MailSend
Error 5 The name 'msg' does not exist in the current context D:\BE630\MailSend\MailSend\Form1.cs 69 13 MailSend
Error 6 The name 'msg' does not exist in the current context D:\BE630\MailSend\MailSend\Form1.cs 70 13 MailSend
Error 7 The name 'msg' does not exist in the current context D:\BE630\MailSend\MailSend\Form1.cs 71 13 MailSend
Error 8 The name 'msg' does not exist in the current context D:\BE630\MailSend\MailSend\Form1.cs 72 13 MailSend
Error 9 The name 'msg' does not exist in the current context D:\BE630\MailSend\MailSend\Form1.cs 74 13 MailSend
Error 10 The name 'msg' does not exist in the current context D:\BE630\MailSend\MailSend\Form1.cs 75 22 MailSend
[no name] 8-Mar-14 3:23am    
If you wrote this or taken from any website then check that there is no declaration for
"msg".
Check that and add that..
Tjeetu 8-Mar-14 3:53am    
how to declare that msg...??
i mean what datatype??



thnks in advance
[no name] 8-Mar-14 4:14am    
It's for mail sending right..??
from where you got this code see there ..

Check my solution below..

Try with following code modifications.



NetworkCredential n = new NetworkCredential(txtFrom.Text, "Jeetendra");

or

NetworkCredential n = new NetworkCredential(txtFrom.Text, "Jeetendra","smtp.xmail.com");


Thanks & Regards
Anand. G
 
Share this answer
 
Comments
Tjeetu 8-Mar-14 4:15am    
can anyone tell what is the problem of "msg" in above code.
it generates following error how to solve it??
Error 1 The name 'msg' does not exist in the current context D:\BE630\MailSend\MailSend\Form1.cs 68 13 MailSend
Error 2 The name 'msg' does not exist in the current context D:\BE630\MailSend\MailSend\Form1.cs 69 13 MailSend
Error 3 The name 'msg' does not exist in the current context D:\BE630\MailSend\MailSend\Form1.cs 70 13 MailSend
Error 4 The name 'msg' does not exist in the current context D:\BE630\MailSend\MailSend\Form1.cs 71 13 MailSend
Error 5 The name 'msg' does not exist in the current context D:\BE630\MailSend\MailSend\Form1.cs 72 13 MailSend
Error 6 The name 'msg' does not exist in the current context D:\BE630\MailSend\MailSend\Form1.cs 74 13 MailSend
Error 7 The name 'msg' does not exist in the current context D:\BE630\MailSend\MailSend\Form1.cs 75 22 MailSend

plz mention the solution also...



thnxx in adv!!
Anand Gunasekaran 8-Mar-14 4:22am    
Add the following code in Button1_Click Event Method then run the code. Tell the bug.

MailMessage msg = new MailMessage();
Tjeetu 8-Mar-14 4:43am    
bugs are..
Error 1 ; expected D:\BE630\MailSend\MailSend\Form1.cs 66 29 MailSend
Error 2 Type expected D:\BE630\MailSend\MailSend\Form1.cs 66 33 MailSend

Anand Gunasekaran 8-Mar-14 4:53am    
Sorry. I made a Mistake Now put
MailMessage msg = new MailMessage();
Tjeetu 8-Mar-14 4:58am    
now there is another bug....
Error 1 Cannot implicitly convert type 'System.Net.NetworkCredential' to 'System.Net.Mail.MailAddress' D:\BE630\MailSend\MailSend\Form1.cs 69 24 MailSend
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900