Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / .NET SDK / April 2004

Tip: Looking for answers? Try searching our database.

Sending email

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Young - 14 Apr 2004 20:48 GMT
Hi,

 I have enabled the smtp server on my WinXP box, which allows me to send
emails from my pc using SmtpMail.Send.  I have written a little program for
a couple of friends (there ip address is dynamic) which gets their ip
address and then emails that address to me.  This address is used so that I
can help them via PC Anywhere when they have problems.  Their pcs will be
setup so that their smtp server is set to my ip which allows them to send
emails via my pc.  The trouble is that I do not understand how to
authenticate them using a username and password.  How would I send a user
name and password to my smtp server so that they can send email through my
server.  Here is some code if it helps..

Thanks in advance.

John

CODE:

// get the mail server address

IPHostEntry ipEntry2=Dns.Resolve(Dns.Resolve(edMailServer.Text).HostName);
//the address of my smtp server

IPAddress [] ipAddr2 = ipEntry2.AddressList;

// first get this pcs IP addresses

IPHostEntry ipEntry=Dns.Resolve(Dns.Resolve("localhost").HostName);  // get
pcs ips

IPAddress [] ipAddr = ipEntry.AddressList;

// now send an email to polomint77@hotmail.com

try

{

// Construct a new mail message and fill it with information from the form

MailMessage aMessage = new MailMessage();

aMessage.From = "IP SENDER";

aMessage.To = edEmailTo.Text;

aMessage.Subject = "IP Request accepted and logged";

// create the ip list

string cs = "";

for (int i = 0; i < ipAddr.Length; i++)

{

cs += ipAddr[i].ToString();

cs += " : ";

}

aMessage.Body = cs;  // got all ips in a string

// Now send the message

SmtpMail.SmtpServer=ipAddr[0].ToString();

SmtpMail.Send(aMessage);  // but cannot send coz I need username and
password to authenticate the user

}

catch(Exception ex)

{

MessageBox.Show(ex.Message);

}
Michael Giagnocavo [MVP] - 14 Apr 2004 21:05 GMT
http://www.codeproject.com/dotnet/SystemWeb_Mail_SMTP_AUTH.asp

That should help you.
-mike
MVP

> Hi,
>
[quoted text clipped - 80 lines]
>
> }
John Young - 14 Apr 2004 21:25 GMT
Thanks for the quick reply, I'll check that out.

Just one more question though, does .NET have any methods for checking
whether a pc is connected to the net?  Or can I try (in code) pinging
microsoft for instance and checking if it fails?

Thanks again.

John

> http://www.codeproject.com/dotnet/SystemWeb_Mail_SMTP_AUTH.asp
>
[quoted text clipped - 86 lines]
> >
> > }
Michael Giagnocavo [MVP] - 14 Apr 2004 22:48 GMT
Yes, the best way to determine if you are on THE Internet (as compared to
being on AN internet) would be to ping some wellknown, internet-only sites.
Not 100% secure (someone could setup a fake DNS server and supply your
program with local IPs), but I'm guessing that's not an issue :).

-mike
MVP

> Thanks for the quick reply, I'll check that out.
>
[quoted text clipped - 104 lines]
>> >
>> > }
John Young - 14 Apr 2004 23:39 GMT
No, that's not an issue.  Only selected people will have this app.  Does
.NET have any methods to ping an IP?

Thanks

John

> Yes, the best way to determine if you are on THE Internet (as compared to
> being on AN internet) would be to ping some wellknown, internet-only sites.
[quoted text clipped - 112 lines]
> >> >
> >> > }
John Young - 14 Apr 2004 21:55 GMT
Ok, I've checked the link you gave me michael, and have coded that into my
app.  All I'm getting now is the CDO not accessible error msg.
I have created a user on my pc and used the username and password for that
user, yet I still cannot send mail.  Here is the code...
Do I need to create a new user through the IIS properties or does it check
the supplied details using whichever users are listed on my pc?

private void GetAndSendIP()

{

// get the mail server address

IPHostEntry ipEntry2=Dns.Resolve(Dns.Resolve(edMailServer.Text).HostName);

IPAddress [] ipAddr2 = ipEntry2.AddressList;

// first get this pcs IP address

IPHostEntry ipEntry=Dns.Resolve(Dns.Resolve("localhost").HostName);

IPAddress [] ipAddr = ipEntry.AddressList;

// now send an email to polomint77@hotmail.com

try

{

// Construct a new mail message and fill it with information from the form

MailMessage aMessage = new MailMessage();

aMessage.From = "IP SENDER";

aMessage.To = edEmailTo.Text;

aMessage.Subject = "IP Request accepted and logged";

// create the ip list

string cs = "";

for (int i = 0; i < ipAddr.Length; i++)

{

cs += ipAddr[i].ToString();

cs += " : ";

}

aMessage.Body = cs;

aMessage.BodyFormat = MailFormat.Text;

aMessage.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"]
= ipAddr2[0].ToString();

aMessage.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverpo
rt"] = 25;

aMessage.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"]=
2;

aMessage.Fields[

"http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;

aMessage.Fields[

"http://schemas.microsoft.com/cdo/configuration/sendusername"] =

"polomint";

aMessage.Fields[

"http://schemas.microsoft.com/cdo/configuration/sendpassword"] =

"16384";

// Now send the message

SmtpMail.SmtpServer=ipAddr[0].ToString();

SmtpMail.Send(aMessage);

}

catch(Exception ex)

{

MessageBox.Show(ex.Message);

}

}

}
Phil Wilson - 14 Apr 2004 22:50 GMT
I don't think CDO is installed by default unless you have a Server OS.
Signature

Phil Wilson
[MVP Windows Installer]

> Ok, I've checked the link you gave me michael, and have coded that into my
> app.  All I'm getting now is the CDO not accessible error msg.
[quoted text clipped - 52 lines]
>
> aMessage.BodyFormat = MailFormat.Text;

aMessage.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"]
> = ipAddr2[0].ToString();

aMessage.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverpo
> rt"] = 25;

aMessage.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"]=
> 2;
>
[quoted text clipped - 33 lines]
>
> }
John Young - 14 Apr 2004 23:38 GMT
Hi,

   CDO is working fine, the problem seems to be using authentication.  I
think I may be using the SMTP server settings incorrectly.
If I send an email with a username and password how does the SMTP server
authenticate the user?  Is there a list somewhere where I can add users?  If
I allow anonymous access then everything works as i should, but I don't want
to allow just anyone to send email through my server..

Any ideas or tutorials on how to correctly set up the IIS SMTP server?

John

> I don't think CDO is installed by default unless you have a Server OS.
> > Ok, I've checked the link you gave me michael, and have coded that into my
[quoted text clipped - 53 lines]
> >
> > aMessage.BodyFormat = MailFormat.Text;

aMessage.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"]
> > = ipAddr2[0].ToString();

aMessage.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverpo
> > rt"] = 25;

aMessage.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"]=
> > 2;
> >
[quoted text clipped - 33 lines]
> >
> > }
Phil Wilson - 15 Apr 2004 17:59 GMT
Search for "authenticated SMTP", see if that helps.
Signature

Phil Wilson
[MVP Windows Installer]

> Hi,
>
[quoted text clipped - 71 lines]
> > >
> > > aMessage.BodyFormat = MailFormat.Text;

aMessage.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"]
> > > = ipAddr2[0].ToString();

aMessage.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverpo
> > > rt"] = 25;

aMessage.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"]=
> > > 2;
> > >
[quoted text clipped - 33 lines]
> > >
> > > }
John Young - 15 Apr 2004 18:42 GMT
Right, I got it working by using a seperate smtp server, instead of using
the IIS SMTP Server.  Now all I'm trying to do is detect whether the pc the
app is running on is connected to the net.  Any ideas?

Thanks

John

> Search for "authenticated SMTP", see if that helps.
> > Hi,
[quoted text clipped - 27 lines]
> > > >
> > > > aMessage.BodyFormat = MailFormat.Text;

aMessage.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"]
> > > > = ipAddr2[0].ToString();

aMessage.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverpo
> > > > rt"] = 25;

aMessage.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"]=
> > > > 2;
> > > >
[quoted text clipped - 34 lines]
> > > >
> > > > }
Phil Wilson - 21 Apr 2004 22:58 GMT
For the internet, there's:
[DllImport("wininet.dll")]
public static extern bool InternetGetConnectedState(int lpdwFlags, int res);

Will that do the job?
Signature

Phil Wilson [MVP Windows Installer]
----

> Right, I got it working by using a seperate smtp server, instead of using
> the IIS SMTP Server.  Now all I'm trying to do is detect whether the pc the
[quoted text clipped - 36 lines]
> > > > >
> > > > > aMessage.BodyFormat = MailFormat.Text;

aMessage.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"]
> > > > > = ipAddr2[0].ToString();

aMessage.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverpo
> > > > > rt"] = 25;

aMessage.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"]=
> > > > > 2;
> > > > >
[quoted text clipped - 34 lines]
> > > > >
> > > > > }
Chad Z. Hower aka Kudzu - 16 Apr 2004 12:51 GMT
> http://www.codeproject.com/dotnet/SystemWeb_Mail_SMTP_AUTH.asp

Also try:
www.indyproject.org

It supports many types of auths, and is free. There is a C# SMTP demo at
www.atozed.com/indy

It also does not need CDO.

--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
     "Programming is an art form that fights back"

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.