Click here to Skip to main content

C#

   
Home > Forums > C#

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page  Show 
  Refresh
GeneralRe: How to check that dsn which is created used for Sql Server or Access using C# PinmemberAwadhendra12343:24 22 Feb '12  
GeneralRe: How to check that dsn which is created used for Sql Server or Access using C# PinmemberPIEBALDconsult4:00 22 Feb '12  
QuestionDetect Marked Checkbox using OCR Pinmemberzead2:12 22 Feb '12  
AnswerRe: Detect Marked Checkbox using OCR PinPopularmemberenhzflep4:44 22 Feb '12  
GeneralRe: Detect Marked Checkbox using OCR Pinmemberzead20:29 22 Feb '12  
GeneralRe: Detect Marked Checkbox using OCR Pinmemberenhzflep20:43 22 Feb '12  
Questionsmtp unknown sender PinmemberCS3423:23 21 Feb '12  
Hello guys!

I am trying to use the following code to send an email to a mail server over a tcp connection. The code works great, however, when I try to send an email to someone, the receipt of my Email alwyes gets unknown sender(From). Am I missing something?
 
TcpClient SmtpServ = new TcpClient("smtp.my.com", 25);
            string Data;
            byte[] szData;
            string CRLF = "\r\n";
 
            try
            {
                // initialization
                NetworkStream NetStrm = SmtpServ.GetStream();
                StreamReader RdStrm = new StreamReader(SmtpServ.GetStream());
                Console.WriteLine(RdStrm.ReadLine());
 
                // say hello to server and send response into log report
                Data = "HELO server" + CRLF;
                szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
                NetStrm.Write(szData, 0, szData.Length);
                Console.WriteLine(RdStrm.ReadLine());
                // send sender data
                Data = "MAIL From:" + " me@test.com" + CRLF;
                szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
                NetStrm.Write(szData, 0, szData.Length);
                Console.WriteLine(RdStrm.ReadLine());
 
                // send receiver data
                Data = "RCPT TO: " + "me@my.net" + CRLF;
                szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
                NetStrm.Write(szData, 0, szData.Length);
                Console.WriteLine(RdStrm.ReadLine());
 
                // send DATA
                Data = "DATA" + CRLF;
                szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
                NetStrm.Write(szData, 0, szData.Length);
                Console.WriteLine(RdStrm.ReadLine());
 
                // send content data
                Data = "SUBJECT: my subject\r\n\r\n";
                Data += "Hello there!\r\n";
                Data += ".\r\n";
                szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
                NetStrm.Write(szData, 0, szData.Length);
                Console.WriteLine(RdStrm.ReadLine());
 
 
                // quit from server SMTP
                Data = "QUIT" + CRLF;
                szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
                NetStrm.Write(szData, 0, szData.Length);
                Console.WriteLine(RdStrm.ReadLine());
 
                // close connection
                NetStrm.Close();
                RdStrm.Close();
                Console.WriteLine("Close connection");
                Console.WriteLine("Send mail successly..");
 
            }
            catch (InvalidOperationException err)
            {
                Console.WriteLine("Error: " + err.ToString());
            }
 

 
Thanks,
AnswerRe: smtp unknown sender PinmvpRichard MacCutchan3:14 22 Feb '12  
Questionadd application to \\root\SecurityCenter2\antispywareproduct as antispyware Pinmemberabhinish23:12 21 Feb '12  
Questionhow can i scann image from scanner in C# PinmemberA7mad_22:55 21 Feb '12  
AnswerRe: how can i scann image from scanner in C# Pinmemberlukeer2:17 22 Feb '12  
Questiontrouble in connecting from C# to Postgre SQL. Pinmemberhellono120:46 21 Feb '12  
AnswerRe: trouble in connecting from C# to Postgre SQL. PinmemberBobJanova21:42 21 Feb '12  
QuestionIntegration of .NET with retail billing machine Pinmembertahernd19:14 21 Feb '12  
AnswerRe: Integration of .NET with retail billing machine PinmvpRichard MacCutchan21:24 21 Feb '12  
AnswerRe: Integration of .NET with retail billing machine PinmemberMycroft Holmes21:39 21 Feb '12  
GeneralRe: Integration of .NET with retail billing machine Pinmembertahernd0:26 22 Feb '12  
QuestionAny difference between Console App and Windows Service for HttpWebRequest..? [Solved] PinmemberTimothy CIAN6:38 21 Feb '12  
AnswerRe: Any difference between Console App and Windows Service for HttpWebRequest..? Pinmemberjschell9:41 21 Feb '12  
GeneralRe: Any difference between Console App and Windows Service for HttpWebRequest..? PinmemberTimothy CIAN10:10 21 Feb '12  
AnswerRe: Any difference between Console App and Windows Service for HttpWebRequest..? PinmvpDave Kreskowiak15:08 21 Feb '12  
GeneralRe: Any difference between Console App and Windows Service for HttpWebRequest..? PinmemberTimothy CIAN3:34 22 Feb '12  
AnswerRe: Any difference between Console App and Windows Service for HttpWebRequest..? [Eureka!] PinmemberTimothy CIAN10:40 22 Feb '12  
GeneralRe: Any difference between Console App and Windows Service for HttpWebRequest..? [Eureka!] Pinmemberjschell11:35 22 Feb '12  
QuestionVisual Studio - Could not load file or assembly 'Microsoft MSXML' PinmemberMember 79805836:27 21 Feb '12  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Beta | 2.5.120517.1 | Last Updated 22 May 2012
Copyright © CodeProject, 1999-2012
All Rights Reserved. Terms of Use
Layout: fixed | fluid