Click here to Skip to main content
16,017,788 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All

I Try Send Message With MailMessage Class But This Error Occurred :
A form Address Must be Specified.

my code snippet

C#
private void SendEmail()
            {    
                System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
    
                System.Net.Mail.Attachment attach = new System.Net.Mail.Attachment(@"C:\MyFile\Instruction.txt");
    
                mail.Attachments.Add(attach);
    
                mail.Body = "";
    
                System.Net.Mail.MailAddress address = new System.Net.Mail.MailAddress("www.aligoglos@yahoo.com");
    
                mail.To.Add(address);
    
                System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("localhost");
    
                client.Send(mail);
     
               mail.Dispose();
    
                MessageBox.Show("Email Sended");
    
            }


thanks all
Posted

1 solution

Hi,
Your error message is self explaining. You have to add sender mail address as well to send mail, so you need to add
 System.Net.Mail.MailAddress fromAddress = new System.Net.Mail.MailAddress("test@yahoo.com");
mail.From.Add(fromAddress);
 
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