Hello All,
This sends an email message OK. But, how do I
attach a file?
// create server SMTP with port 25
string ServSMTP = "mycompany.com";
string sFrom = "su*****@mycompany.com";
string sTo = "we*******@bmycompany.com";
string sSubject = "Subject Test";
string sMessage = "Message Body Test";
TcpClient SmtpServ = new TcpClient(ServSMTP,25);
string Data;
byte[] szData;
string CRLF = "\r\n";
try
{
// initialization
NetworkStream NetStrm = SmtpServ.GetStream();
StreamReader RdStrm= new StreamReader(SmtpServ.GetStream
());
// say hello to server and send response into log report
Data = "EHLO mycompany.com " + CRLF; szData =
System.Text.Encoding.ASCII.GetBytes(Data.ToCharArr ay());
NetStrm.Write(szData,0,szData.Length);
// send sender data
Data = "MAIL FROM:" + sFrom + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes
(Data.ToCharArray());
NetStrm.Write(szData,0,szData.Length);
// send receiver data
Data = "RCPT TO:" + sTo + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes
(Data.ToCharArray());
NetStrm.Write(szData,0,szData.Length);
// send DATA
Data = "DATA " + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes
(Data.ToCharArray());
NetStrm.Write(szData,0,szData.Length);
// send content data
Data = "SUBJECT: " + sSubject + CRLF + sMessage + CRLF
+ "." + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes
(Data.ToCharArray());
NetStrm.Write(szData,0,szData.Length);
// quit from server SMTP
Data = "QUIT " + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes
(Data.ToCharArray());
NetStrm.Write(szData,0,szData.Length);
// close connection
NetStrm.Close();
RdStrm.Close();
TIA,
Jacques 2 5699
Use MailMessage, MailAttachment and SmtpMail classes from MailAttachment
namespace
--
-------------------------
"Manish Agarwal"- <ma***********@hotmail.com>
"Jacques" <an*******@discussions.microsoft.com> wrote in message
news:0c****************************@phx.gbl... Hello All,
This sends an email message OK. But, how do I attach a file?
// create server SMTP with port 25 string ServSMTP = "mycompany.com"; string sFrom = "su*****@mycompany.com"; string sTo = "we*******@bmycompany.com"; string sSubject = "Subject Test"; string sMessage = "Message Body Test";
TcpClient SmtpServ = new TcpClient(ServSMTP,25);
string Data; byte[] szData; string CRLF = "\r\n";
try { // initialization NetworkStream NetStrm = SmtpServ.GetStream(); StreamReader RdStrm= new StreamReader(SmtpServ.GetStream ());
// say hello to server and send response into log report Data = "EHLO mycompany.com " + CRLF; szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArr ay()); NetStrm.Write(szData,0,szData.Length);
// send sender data Data = "MAIL FROM:" + sFrom + CRLF; szData = System.Text.Encoding.ASCII.GetBytes (Data.ToCharArray()); NetStrm.Write(szData,0,szData.Length);
// send receiver data Data = "RCPT TO:" + sTo + CRLF; szData = System.Text.Encoding.ASCII.GetBytes (Data.ToCharArray()); NetStrm.Write(szData,0,szData.Length);
// send DATA Data = "DATA " + CRLF; szData = System.Text.Encoding.ASCII.GetBytes (Data.ToCharArray()); NetStrm.Write(szData,0,szData.Length);
// send content data Data = "SUBJECT: " + sSubject + CRLF + sMessage + CRLF + "." + CRLF; szData = System.Text.Encoding.ASCII.GetBytes (Data.ToCharArray()); NetStrm.Write(szData,0,szData.Length);
// quit from server SMTP Data = "QUIT " + CRLF; szData = System.Text.Encoding.ASCII.GetBytes (Data.ToCharArray()); NetStrm.Write(szData,0,szData.Length);
// close connection NetStrm.Close(); RdStrm.Close();
TIA, Jacques
Use MailMessage, MailAttachment and SmtpMail classes from System.Web.Mail
namespace
--
-------------------------
"Manish Agarwal"- <ma***********@hotmail.com>
"Jacques" <an*******@discussions.microsoft.com> wrote in message
news:0c****************************@phx.gbl... Hello All,
This sends an email message OK. But, how do I attach a file?
// create server SMTP with port 25 string ServSMTP = "mycompany.com"; string sFrom = "su*****@mycompany.com"; string sTo = "we*******@bmycompany.com"; string sSubject = "Subject Test"; string sMessage = "Message Body Test";
TcpClient SmtpServ = new TcpClient(ServSMTP,25);
string Data; byte[] szData; string CRLF = "\r\n";
try { // initialization NetworkStream NetStrm = SmtpServ.GetStream(); StreamReader RdStrm= new StreamReader(SmtpServ.GetStream ());
// say hello to server and send response into log report Data = "EHLO mycompany.com " + CRLF; szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArr ay()); NetStrm.Write(szData,0,szData.Length);
// send sender data Data = "MAIL FROM:" + sFrom + CRLF; szData = System.Text.Encoding.ASCII.GetBytes (Data.ToCharArray()); NetStrm.Write(szData,0,szData.Length);
// send receiver data Data = "RCPT TO:" + sTo + CRLF; szData = System.Text.Encoding.ASCII.GetBytes (Data.ToCharArray()); NetStrm.Write(szData,0,szData.Length);
// send DATA Data = "DATA " + CRLF; szData = System.Text.Encoding.ASCII.GetBytes (Data.ToCharArray()); NetStrm.Write(szData,0,szData.Length);
// send content data Data = "SUBJECT: " + sSubject + CRLF + sMessage + CRLF + "." + CRLF; szData = System.Text.Encoding.ASCII.GetBytes (Data.ToCharArray()); NetStrm.Write(szData,0,szData.Length);
// quit from server SMTP Data = "QUIT " + CRLF; szData = System.Text.Encoding.ASCII.GetBytes (Data.ToCharArray()); NetStrm.Write(szData,0,szData.Length);
// close connection NetStrm.Close(); RdStrm.Close();
TIA, Jacques This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: nick |
last post by:
The code always returen the following error at fclose(fp).
Fatal error: Maximum execution time of 30 seconds exceeded in...
|
by: marsandys |
last post by:
Hello, I have this code below, which I am trying to have it send HTML
formatted mail with embedded images. I can get this to send the mail,
but it...
|
by: Sam |
last post by:
Hi,
I want to be able to send an email w/ attachment. I have an INPUT
Type="File" HTMLControl on the page. User selects the attachment using this...
|
by: Robbie De Sutter |
last post by:
Hello,
How do I open a new, empty e-mail message from the default e-mail client
whereby the sender is given and a file is attached?
Currently...
|
by: Cimento Cola |
last post by:
Hello all.
Hope anyone can help me!
I have this form, with:
Please choose your file: (browse)
The main purpose is the user to select a...
|
by: =?Utf-8?B?SHVnaA==?= |
last post by:
Hi There,
I use follow code to send email inside VB.NET 2005. It does not work well.
Error message of "Failure sending email" would occue. ...
|
by: shil |
last post by:
Hi,
I'm using FW 2.0 to send an email with an attachment using
System.Net.Mail class. If I try to attach a file from my file system,
I could...
|
by: Chitu03 |
last post by:
Hi
I am already send a mail using Php with some attachement into it. My Problem is the attachement file is in my Database(mysql). I don't know...
|
by: sxwend |
last post by:
I am trying to use the following post results (http://www.thescripts.com/forum/thread189759.html) and add another requirement. I need to send the...
|
by: deepaks85 |
last post by:
Dear All,
I want to send some data through a form with Multiple attachment in an HTML Format. I have tried it but it is not working for me. I am...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
|
by: jalbright99669 |
last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
|
by: Matthew3360 |
last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function.
Here is my code.
...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...
| |