473,416 Members | 1,536 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

How to send an e-mail

I have a service that needs to send e-mail alerts. I have been attempting
to use the System.Net.Mail function from .NET but this seems to require the
IIS be installed and running. Since some of my customers are not really
happy with having the IIS installed, not being used except to send e-mail
this is becoming a problem.

I have also tried using a little program from code project for sending
e-mail which works great on older servers but does not work on newer servers
because security which I don't have time to resolve.

Is there a better/easier way of doing this?

Regards,
John
Nov 17 '05 #1
6 3238
Here is little smtp client I did in C# (no cdo or IIS required).
http://spaces.msn.com/members/staceyw/Blog/cns!1pnsZpX0fPvDxLKC6rAAhLsQ!361.entry

--
William Stacey [MVP]

"John J. Hughes II" <no@invalid.com> wrote in message
news:Ob**************@TK2MSFTNGP15.phx.gbl...
I have a service that needs to send e-mail alerts. I have been attempting
to use the System.Net.Mail function from .NET but this seems to require the
IIS be installed and running. Since some of my customers are not really
happy with having the IIS installed, not being used except to send e-mail
this is becoming a problem.

I have also tried using a little program from code project for sending
e-mail which works great on older servers but does not work on newer
servers because security which I don't have time to resolve.

Is there a better/easier way of doing this?

Regards,
John

Nov 17 '05 #2
William,

Looks sort of like the one I had the security issue with but I will try it,
thanks.

Regards,
John
Nov 17 '05 #3
"John J. Hughes II" <no@invalid.com> wrote in
news:Ob**************@TK2MSFTNGP15.phx.gbl:
I have a service that needs to send e-mail alerts. I have been
attempting to use the System.Net.Mail function from .NET but this
seems to require the IIS be installed and running. Since some of my


Yes, it has installation requirements.

See here for an alternate solution:
http://www.codeproject.com/csharp/IndySMTP.asp
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Make your ASP.NET applications run faster
http://www.atozed.com/IntraWeb/
Nov 17 '05 #4
William,

It works with my local ISP so I am forward it to the problem customers :),
see how far that gets me. I am no longer with the ISP my last attempt at
this failed with so...

I had to change the following.

IPAddress[] ips = Dns.GetHostAddresses(SmtpServer);

TO THIS:

IPHostEntry iphe = Dns.GetHostByName(SmtpServer);
IPAddress[] ips = iphe.AddressList;
AND I removed this, it was giving me a 500 error.

//CheckReply(sr, SMTPResponse.QUIT_SUCCESS);

Regards,
John
Nov 17 '05 #5
Here is a mail class I used before there was a mailer namespace. It works
with any smtp server. I know it makes the calls manually but I used it in a
mass email app with over 60,000 recipients to tell players at sorren.com
announcements. It is solid code.

using System;

using System.IO;

using System.Net;

using System.Net.Sockets;

using System.Text;

using System.Diagnostics;

namespace Emailer

{

/// <summary>

/// Summary description for Class1.

/// </summary>

public class Mailer

{

private string strEmailServer;

private string strSendTo;

private string strMailFrom;

private string strSubject;

private string strBody;

public static TcpClient tcpc = new TcpClient(); // public static so is
thread safe

public static NetworkStream nwstream; // public static so is thread safe

public Mailer(string SMTPServer, string Sender)

{

this.SMTPServer = SMTPServer;

this.Sender = Sender;

}

public string SMTPServer

{

get

{

return strEmailServer;

}

set

{

strEmailServer = value;

}

}

public string Recipient

{

get

{

return strSendTo;

}

set

{

strSendTo = value;

}

}

public string Sender

{

get

{

return strMailFrom;

}

set

{

strMailFrom = value;

}

}

public string Subject

{

get

{

return strSubject;

}

set

{

strSubject = value;

}

}

public string Body

{

get

{

return strBody;

}

set

{

strBody = value;

}

}

public string Send(string Recipient, string Subject, string Body)

{

this.Subject=Subject;

return Send(Recipient, Body);

}

public string Send(string Recipient, string Body)

{

this.Recipient=Recipient;

this.Body=Body;

return Send();

}

public string Send()

{

string strResponse;

StringBuilder smtpLog = new StringBuilder();

Debug.WriteLine("Mailer.Send() : Requesting Lock on 'tcpc'...");

lock(tcpc)

{

Debug.WriteLine("Mailer.Send() : Lock on 'tcpc' is approved.");

Debug.WriteLine("Mailer.Send() : Creating TcpClient");

// TcpClient tcpc = new TcpClient(); made public static so is thread safe

tcpc = new TcpClient();

try

{

tcpc.Connect(strEmailServer, 25);

}

catch (SocketException socketEx)

{

Debug.WriteLine("Mailer.Send() : Connection Error: " + socketEx.ToString());

return "Connection Error: " + socketEx.ToString();

}

// string strResponse;

// string strFullResponse=""; // needed to be defined outside "lock"-ed code

Debug.WriteLine("Mailer.Send() : Getting NetworkStream");

// made public static so is thread safe

// NetworkStream nwstream = tcpc.GetStream();

nwstream = tcpc.GetStream();

Debug.WriteLine("Mailer.Send() : Writing to Stream");

try

{ string smtp;

ReadFromStream(ref nwstream, out strResponse);

smtpLog.Append(strResponse);

smtp = "HELO myhost";

WriteToStream(ref nwstream, smtp);

smtpLog.Append(smtp + Environment.NewLine);

ReadFromStream(ref nwstream, out strResponse);

smtpLog.Append(strResponse);

smtp = "MAIL FROM: " + strMailFrom;

WriteToStream(ref nwstream, smtp);

smtpLog.Append(smtp + Environment.NewLine);

ReadFromStream(ref nwstream, out strResponse);

smtpLog.Append(strResponse);

smtp = "RCPT TO: " + strSendTo;

WriteToStream(ref nwstream, smtp);

smtpLog.Append(smtp + Environment.NewLine);

ReadFromStream(ref nwstream, out strResponse);

smtpLog.Append(strResponse);

smtp = "DATA";

WriteToStream(ref nwstream, smtp);

smtpLog.Append(smtp + Environment.NewLine);

ReadFromStream(ref nwstream, out strResponse);

smtpLog.Append(strResponse);

smtp = "From: " + strMailFrom;

WriteToStream(ref nwstream, smtp);

smtpLog.Append(smtp + Environment.NewLine);

smtp = "Subject: " + strSubject;

WriteToStream(ref nwstream, smtp);

smtpLog.Append(smtp + Environment.NewLine);

smtp = "To: " + strSendTo;

WriteToStream(ref nwstream, smtp);

smtpLog.Append(smtp + Environment.NewLine);

smtp = "";

WriteToStream(ref nwstream, "");

smtpLog.Append(smtp + Environment.NewLine);

smtp = strBody;

WriteToStream(ref nwstream, smtp);

smtpLog.Append(smtp + Environment.NewLine);

smtp = "\r\n.";

WriteToStream(ref nwstream, smtp);

smtpLog.Append(smtp + Environment.NewLine);

ReadFromStream(ref nwstream, out strResponse);

smtpLog.Append(strResponse);

}

catch

{

Debug.WriteLine("Mailer.Send() : Problem Reading/writing");

}

Debug.WriteLine("Mailer.Send() : Closing NetworkStream");

nwstream.Close();

Debug.WriteLine("Mailer.Send() : Closing TcpClient");

tcpc.Close();

Debug.WriteLine("Mailer.Send() : Releasing Lock on 'tcpc'...");

} // lock(tcpc) {

Debug.WriteLine("Mailer.Send() : Lock on 'tcpc' is released.");

Debug.WriteLine("Mailer.Send() : Returning Full Response");

return smtpLog.ToString();

}

private bool WriteToStream(ref NetworkStream nwstream, string strLine)

{

string strString2Send = strLine + "\r\n";

Byte[] arr2Send = Encoding.ASCII.GetBytes(strString2Send.ToCharArray ());

try

{

nwstream.Write(arr2Send, 0, arr2Send.Length);

}

catch

{

return false;

}

return true;

}

private bool ReadFromStream(ref NetworkStream nwstream, out string
strMessage)

{

byte[] readBuffer = new byte[4096];

int nLength = nwstream.Read(readBuffer, 0, readBuffer.Length);

strMessage = Encoding.ASCII.GetString(readBuffer, 0, nLength);

return (3 <= readBuffer[0]); // 2 success, 3 informational

}

}

}
"John J. Hughes II" <no@invalid.com> wrote in message
news:Ob**************@TK2MSFTNGP15.phx.gbl...
I have a service that needs to send e-mail alerts. I have been attempting
to use the System.Net.Mail function from .NET but this seems to require the
IIS be installed and running. Since some of my customers are not really
happy with having the IIS installed, not being used except to send e-mail
this is becoming a problem.

I have also tried using a little program from code project for sending
e-mail which works great on older servers but does not work on newer
servers because security which I don't have time to resolve.

Is there a better/easier way of doing this?

Regards,
John

Nov 17 '05 #6
Some of that was fx2.0 specific stuff - sorry did not mention that.

--
William Stacey [MVP]

"John J. Hughes II" <no@invalid.com> wrote in message
news:u0**************@TK2MSFTNGP14.phx.gbl...
William,

It works with my local ISP so I am forward it to the problem customers :),
see how far that gets me. I am no longer with the ISP my last attempt at
this failed with so...

I had to change the following.

IPAddress[] ips = Dns.GetHostAddresses(SmtpServer);

TO THIS:

IPHostEntry iphe = Dns.GetHostByName(SmtpServer);
IPAddress[] ips = iphe.AddressList;
AND I removed this, it was giving me a 500 error.

//CheckReply(sr, SMTPResponse.QUIT_SUCCESS);

Regards,
John

Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tom Brown | last post by:
Hi, I have what seems to be a simple problem. But I can not for the life of me find a way to send an integer over a socket. The send method will only accept strings. Here is what I am trying to...
9
by: Etienne Charland | last post by:
Hi, there is an application running on a remote desktop (under Citrix ICA, but the same problem applies for RDC or PC Anywhere). Now, I want to send keys to the remote application from a local app....
5
by: Pete Loveall | last post by:
I have a server application that monitors a private local queue for messages. The message sent to it has a label and a response queue defined. It works correctly when the queue is accessed via...
1
by: Kitchen Bin | last post by:
Hi. I am trying to use Sockets to do multiple Send and Receives via HTTP (not simultaneously). A first pair of Send/Receives works fine and sure enough I receive HTML back, but the next...
0
by: zhimin | last post by:
Hi, I'm writing a program to send large file(100m) through dotnet using TCPListener & TCPClient, I'm sending the file with a ask and response loop: 1. Client send a flag 1 to server indicate it...
1
by: GrantS | last post by:
I need to use a sendkeys key combination to automate the "accept files" that a remote user wants to send to me via Windows messenger. I am using automation to work with Windows Messenger client in...
3
by: Sara | last post by:
HI, I want to code a program to detect GSM mobile (any kind) which connected through serial port to computer and then be able to send SMS through this mobile phone to other mobile phones, could...
1
by: Hasan O | last post by:
hi , I have a problem with socket.send mesajlar = Encoding.ASCII.GetBytes("UGIR"); socketResultValue = socket.Send(mesajlar,0,mesajlar.Length, SocketFlags.None); socketResultValue =...
3
by: ultr | last post by:
Hello, I have read that send() may not send whole message and returns the nuber of bytes sent, so that we can handle the rest of the message. Is it true, because i have tested sending even 1MB...
0
by: Xionbox | last post by:
Hello everybody, The error I have seems very easy to solve, but for some odd reason I can't seem to solve it. Anyways, here's my "setup". I created a server running on localhost:1200 (telnet...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.