I want my users to send emails from a Windows app that I am developing in
Visual Basic.NET 2003. I found a good example of sending email to a SMTP
server using the SmtpMail class. However, using this, it seems, that the
user must install IIS on their computer. Isn't there a class that will
detect whatever mail server is available on a computer and use that? How do
I create this functionality without having the user add any other programs or
change any previously defined configurations - just use their computer's
email system?
Thanks,
joe 13 3168
You need a SMTP server somewhere. Mail needs to be queued. If you program
exits before you mail is sent, the process needs to keep running.
How about setting up a central IIS / SMTP server? It will still work with
SmtpMail.
-A
"joe215" <jo****@discussions.microsoft.com> wrote in message
news:C6**********************************@microsof t.com... I want my users to send emails from a Windows app that I am developing in Visual Basic.NET 2003. I found a good example of sending email to a SMTP server using the SmtpMail class. However, using this, it seems, that the user must install IIS on their computer. Isn't there a class that will detect whatever mail server is available on a computer and use that? How do I create this functionality without having the user add any other programs or change any previously defined configurations - just use their computer's email system?
Thanks, joe
On Thu, 10 Nov 2005 09:45:02 -0800, joe215 wrote: I want my users to send emails from a Windows app that I am developing in Visual Basic.NET 2003. I found a good example of sending email to a SMTP server using the SmtpMail class. However, using this, it seems, that the user must install IIS on their computer.
Not true. Your example must be assuming that, since installing IIS by
default sets up an SMTP relay server. However, any SMTP server that your
program can reach will suffice.
Isn't there a class that will detect whatever mail server is available on a computer and use that?
Private Function DetectSMTPServer( _
Optional ByVal host As String = "127.0.0.1") _
As Boolean
Dim tcp As New System.Net.Sockets.TcpClient
Dim ServerExists As Boolean = False
Try
tcp.Connect(host, 25)
ServerExists = True
Catch ex As Exception
ServerExists = False
Finally
tcp.Close()
End Try
Return ServerExists
End Function
This function returns true if there's an SMTP server answering at the
specified location. If you don't specify, it assumes the local machine.
How do I create this functionality without having the user add any other programs or change any previously defined configurations - just use their computer's email system?
If you really want to use "their computer's email system", you might look
into MAPI. Here's some code I found that uses Outlook to send an email:
Dim mOutLookApp As Outlook.Application
Dim mNameSpace As Outlook.NameSpace
Dim mItem As Outlook.MailItem
Set mOutLookApp = New Outlook.Application
Set mNameSpace = mOutLookApp.GetNamespace("MAPI")
mNameSpace.Logon ,, False, True
Set mItem = mOutLookApp.CreateItem(olMailItem)
mItem.To = strEmailAddress
mItem.Subject = "This is for you"
mItem.HTMLBody = strMessage
mItem.Sensitivity = olConfidential
mItem.Importance = olImportanceHigh
mItem.Send
Or you could attempt to use the destination mail host for the address
you're sending to, by using DNS to look up the MX record for the
destination domain. No built-in classes to do this simply, but a few
people have written them. See http://www.google.com/search?q=vb.net+MX+lookup
The following free COM object claims to do the MX lookup internally, giving
a very small footprint. But it's COM: http://www.visualbuilder.com/compone...id=360&devid=1
You could go crazy and scan the local LAN for an open port 25.
Or you could just ask the user if they know their mail server's name.
That's probably safe. Maybe use that as a default option, if other methods
fail.
To Ross and Andrew who responded to my "Sending Email" question. Let me
refine my question, especially now that I have looked back at the SMTP
example that I mentioned previously.
The example that I am using comes from the MS Book, "101 Visual Basic.NET
Applications". It is Application #75 in the book. When I run it, I get a
message that I don't have an SMTP Mail Server on my computer - which is not
true. Looking back at the discussion in the book, it says to change the
application setting in app.config to point to the server. The app.config
file contains the following information:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="SmtpMail.SmtpServer" value="127.0.0.1"/>
</appSettings>
</configuration>
So, now my question is how do I find the 'value' (which I assume is an IP
address) for the SmtpServer? And, how would I do this programmatically so
that my users can install my program on their computer, the program can
identify the location of their Smtp Server, and emails can be sent from the
app?
"Ross Presser" wrote: On Thu, 10 Nov 2005 09:45:02 -0800, joe215 wrote:
I want my users to send emails from a Windows app that I am developing in Visual Basic.NET 2003. I found a good example of sending email to a SMTP server using the SmtpMail class. However, using this, it seems, that the user must install IIS on their computer.
Not true. Your example must be assuming that, since installing IIS by default sets up an SMTP relay server. However, any SMTP server that your program can reach will suffice.
Isn't there a class that will detect whatever mail server is available on a computer and use that?
Private Function DetectSMTPServer( _ Optional ByVal host As String = "127.0.0.1") _ As Boolean Dim tcp As New System.Net.Sockets.TcpClient Dim ServerExists As Boolean = False Try tcp.Connect(host, 25) ServerExists = True Catch ex As Exception ServerExists = False Finally tcp.Close() End Try Return ServerExists End Function
This function returns true if there's an SMTP server answering at the specified location. If you don't specify, it assumes the local machine.
How do I create this functionality without having the user add any other programs or change any previously defined configurations - just use their computer's email system?
If you really want to use "their computer's email system", you might look into MAPI. Here's some code I found that uses Outlook to send an email:
Dim mOutLookApp As Outlook.Application Dim mNameSpace As Outlook.NameSpace Dim mItem As Outlook.MailItem
Set mOutLookApp = New Outlook.Application Set mNameSpace = mOutLookApp.GetNamespace("MAPI") mNameSpace.Logon ,, False, True
Set mItem = mOutLookApp.CreateItem(olMailItem) mItem.To = strEmailAddress mItem.Subject = "This is for you" mItem.HTMLBody = strMessage
mItem.Sensitivity = olConfidential mItem.Importance = olImportanceHigh
mItem.Send
Or you could attempt to use the destination mail host for the address you're sending to, by using DNS to look up the MX record for the destination domain. No built-in classes to do this simply, but a few people have written them. See http://www.google.com/search?q=vb.net+MX+lookup
The following free COM object claims to do the MX lookup internally, giving a very small footprint. But it's COM:
http://www.visualbuilder.com/compone...id=360&devid=1
You could go crazy and scan the local LAN for an open port 25.
Or you could just ask the user if they know their mail server's name. That's probably safe. Maybe use that as a default option, if other methods fail.
joe215 wrote: I want my users to send emails from a Windows app that I am developing in Visual Basic.NET 2003. I found a good example of sending email to a SMTP server using the SmtpMail class. However, using this, it seems, that the user must install IIS on their computer. Isn't there a class that will detect whatever mail server is available on a computer and use that? How do I create this functionality without having the user add any other programs or change any previously defined configurations - just use their computer's email system?
Unlike Linux, where a client runs a sendmail server by default, most XP
machines don't have a running 'mail server'. They typically connect to
a remote mail server by IP or by name. That server can be configured
in the SMPTServer object just as easily as a 'local' email server.
In fact, you can put it in the app.config file and use the same one for
everyone that can relay on that server.
Thanks, John. I did finally come to that realization. However, I'm not
knowledgeable about SMTP Servers. So now my question is:
Given an app.config file similar to the one below:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="SmtpMail.SmtpServer" value="127.0.0.1"/>
</appSettings>
</configuration>
My question is how do I find the IP address for the SmtpServer? And, how
would I do this programmatically so that my users can install my program on
their computer, the program can identify the location of their Smtp Server,
and emails can be sent from the app?
Thanks,
Joe
"John A. Bailo" wrote: joe215 wrote: I want my users to send emails from a Windows app that I am developing in Visual Basic.NET 2003. I found a good example of sending email to a SMTP server using the SmtpMail class. However, using this, it seems, that the user must install IIS on their computer. Isn't there a class that will detect whatever mail server is available on a computer and use that? How do I create this functionality without having the user add any other programs or change any previously defined configurations - just use their computer's email system?
Unlike Linux, where a client runs a sendmail server by default, most XP machines don't have a running 'mail server'. They typically connect to a remote mail server by IP or by name. That server can be configured in the SMPTServer object just as easily as a 'local' email server.
In fact, you can put it in the app.config file and use the same one for everyone that can relay on that server.
Well, it's tricky.
You have to let us know is this to be deployed internally on an
corporate network or widespread over the Internet?
If the latter then you are talking about pointing it to their ISP's
smptserver (that they use for Outlook Express or Thunderbird). If that
is the case, you would need to either
(a) run a config/install script that requests that IP
(b) read the registry or profile settings to pick out he smtp address
If it's a corporate network, then you would need to find if they run a
sendmail server or have a IIS/Smtp server that lets people relay on the
server.
joe215 wrote: Thanks, John. I did finally come to that realization. However, I'm not knowledgeable about SMTP Servers. So now my question is:
Given an app.config file similar to the one below:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="SmtpMail.SmtpServer" value="127.0.0.1"/> </appSettings> </configuration>
My question is how do I find the IP address for the SmtpServer? And, how would I do this programmatically so that my users can install my program on their computer, the program can identify the location of their Smtp Server, and emails can be sent from the app?
Thanks, Joe
"John A. Bailo" wrote:
joe215 wrote:
I want my users to send emails from a Windows app that I am developing in Visual Basic.NET 2003. I found a good example of sending email to a SMTP server using the SmtpMail class. However, using this, it seems, that the user must install IIS on their computer. Isn't there a class that will detect whatever mail server is available on a computer and use that? How do I create this functionality without having the user add any other programs or change any previously defined configurations - just use their computer's email system?
Unlike Linux, where a client runs a sendmail server by default, most XP machines don't have a running 'mail server'. They typically connect to a remote mail server by IP or by name. That server can be configured in the SMPTServer object just as easily as a 'local' email server.
In fact, you can put it in the app.config file and use the same one for everyone that can relay on that server.
"joe215" <jo****@discussions.microsoft.com> wrote in message
news:2B**********************************@microsof t.com... The example that I am using comes from the MS Book, "101 Visual Basic.NET Applications". It is Application #75 in the book. When I run it, I get a message that I don't have an SMTP Mail Server on my computer - which is not true. Looking back at the discussion in the book, it says to change the application setting in app.config to point to the server. The app.config file contains the following information:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="SmtpMail.SmtpServer" value="127.0.0.1"/> </appSettings> </configuration>
You do realize that 127.0.0.1 is the loopback address for your local
computer. Not sure why your example cannot find your local SMTP server if
you truely have it installed and working. Sometimes you'll see localhost
used in place of 127.0.0.1. Make sure you 127.0.0.1 allowed for relaying.
Control Panel->Admin Tools->IIS->Right-click default SMTP
server->Properties->Access Tab->Relay button->add 127.0.0.1.
So, now my question is how do I find the 'value' (which I assume is an IP address) for the SmtpServer? And, how would I do this programmatically so that my users can install my program on their computer, the program can identify the location of their Smtp Server, and emails can be sent from the app?
I would imagine you are going to have to have a way for the users of your
app to specifiy their ISP's smtp server address inside your app (either an
IP address or its domain name (example: smtp.comcast.net ). Just like you
have to do when setting up an email account in Outlook Express.
Greg
This is to be a Windows app that can be used on any computer system whether
it is on a corporate network or a home computer.
So, where do I look in the registry to obtain the smtp address?
And, how do I programmatically obtain the necessary information about smtp
on a computer in a corporate network?
Thanks.
"John A. Bailo" wrote: Well, it's tricky.
You have to let us know is this to be deployed internally on an corporate network or widespread over the Internet?
If the latter then you are talking about pointing it to their ISP's smptserver (that they use for Outlook Express or Thunderbird). If that is the case, you would need to either
(a) run a config/install script that requests that IP (b) read the registry or profile settings to pick out he smtp address
If it's a corporate network, then you would need to find if they run a sendmail server or have a IIS/Smtp server that lets people relay on the server. joe215 wrote: Thanks, John. I did finally come to that realization. However, I'm not knowledgeable about SMTP Servers. So now my question is:
Given an app.config file similar to the one below:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="SmtpMail.SmtpServer" value="127.0.0.1"/> </appSettings> </configuration>
My question is how do I find the IP address for the SmtpServer? And, how would I do this programmatically so that my users can install my program on their computer, the program can identify the location of their Smtp Server, and emails can be sent from the app?
Thanks, Joe
"John A. Bailo" wrote:
joe215 wrote:
I want my users to send emails from a Windows app that I am developing in Visual Basic.NET 2003. I found a good example of sending email to a SMTP server using the SmtpMail class. However, using this, it seems, that the user must install IIS on their computer. Isn't there a class that will detect whatever mail server is available on a computer and use that? How do I create this functionality without having the user add any other programs or change any previously defined configurations - just use their computer's email system?
Unlike Linux, where a client runs a sendmail server by default, most XP machines don't have a running 'mail server'. They typically connect to a remote mail server by IP or by name. That server can be configured in the SMPTServer object just as easily as a 'local' email server.
In fact, you can put it in the app.config file and use the same one for everyone that can relay on that server.
I don't know that there is a programmatic method of finding the local SMTP
server or that it is listed anywhere in the registry. You might be able to
check for the existance of a local SMTP server but I don't think you will
find a listing in the registry pointing to a remote server. SMTP is a
service that you will have to configure on either your local machine or a
server and then point your application at that SMTP server.
Things are complicated by the fact that a significant number of ISPs don't
allow you to relay SMTP traffic from within their networks using your own
SMTP server. This is done to combat spam.
-Andrew
"joe215" <jo****@discussions.microsoft.com> wrote in message
news:9A**********************************@microsof t.com... This is to be a Windows app that can be used on any computer system whether it is on a corporate network or a home computer.
So, where do I look in the registry to obtain the smtp address?
And, how do I programmatically obtain the necessary information about smtp on a computer in a corporate network?
Thanks.
"John A. Bailo" wrote:
Well, it's tricky.
You have to let us know is this to be deployed internally on an corporate network or widespread over the Internet?
If the latter then you are talking about pointing it to their ISP's smptserver (that they use for Outlook Express or Thunderbird). If that is the case, you would need to either
(a) run a config/install script that requests that IP (b) read the registry or profile settings to pick out he smtp address
If it's a corporate network, then you would need to find if they run a sendmail server or have a IIS/Smtp server that lets people relay on the server. joe215 wrote: > Thanks, John. I did finally come to that realization. However, I'm > not > knowledgeable about SMTP Servers. So now my question is: > > Given an app.config file similar to the one below: > > <?xml version="1.0" encoding="utf-8" ?> > <configuration> > <appSettings> > <add key="SmtpMail.SmtpServer" value="127.0.0.1"/> > </appSettings> > </configuration> > > My question is how do I find the IP address for the SmtpServer? And, > how > would I do this programmatically so that my users can install my > program on > their computer, the program can identify the location of their Smtp > Server, > and emails can be sent from the app? > > Thanks, > Joe > > "John A. Bailo" wrote: > > >>joe215 wrote: >> >>>I want my users to send emails from a Windows app that I am developing >>>in >>>Visual Basic.NET 2003. I found a good example of sending email to a >>>SMTP >>>server using the SmtpMail class. However, using this, it seems, that >>>the >>>user must install IIS on their computer. Isn't there a class that >>>will >>>detect whatever mail server is available on a computer and use that? >>>How do >>>I create this functionality without having the user add any other >>>programs or >>>change any previously defined configurations - just use their >>>computer's >>>email system? >> >>Unlike Linux, where a client runs a sendmail server by default, most XP >>machines don't have a running 'mail server'. They typically connect >>to >>a remote mail server by IP or by name. That server can be configured >>in the SMPTServer object just as easily as a 'local' email server. >> >>In fact, you can put it in the app.config file and use the same one for >>everyone that can relay on that server. >>
On Thu, 10 Nov 2005 15:10:07 -0800, joe215 wrote: So, where do I look in the registry to obtain the smtp address?
It won't be in the registry, unless there is a email client installed on
the machine configured to use it -- which there very well may be; most
people who use computers also use email. In which case it depends on the
email client: Outlook Express, Outlook 2000, Outlook 2003, Eudora, Netscape
..... there's no set place.
And, how do I programmatically obtain the necessary information about smtp on a computer in a corporate network?
As I said in my previous message, you *could* scan the local LAN to see if
any machine has an open port 25. This can be considered unfriendly
behavior, though, and you should probably ask the user permission before
beginning a scan.
Another slightly sneaky way to do it would be to test all hostnames that
are in the local machine's DNS cache. If the user has been using email
lately, chances are his mail server will appear there. Shell out to the
commandline
IPCONFIG /DISPLAYDNS
and capture the results to a file. Go through the result file and extract
the host names from lines which contain the words "Record Name".
If you turn up empty, prompt the user to check his email or send a test
email, and try again.
He could also take some educated guesses.
Get the domain name of the host and put the word "mail" in front of it,
and use
mail.mydomainname.com
That is typically the name of the smtp/sendmail server on port 25.
It wouldn't always work of course.
An alternative is to run your own sendmail server or find one that
allows relaying and then you would just need to test to see if they can
access it (that is, port 25 is not blocked, as you mention).
If either of those two options are not possible, then the application
should throw a dialog saying "enter smpt/sendmail server".
Ross Presser wrote: On Thu, 10 Nov 2005 15:10:07 -0800, joe215 wrote:
So, where do I look in the registry to obtain the smtp address?
It won't be in the registry, unless there is a email client installed on the machine configured to use it -- which there very well may be; most people who use computers also use email. In which case it depends on the email client: Outlook Express, Outlook 2000, Outlook 2003, Eudora, Netscape .... there's no set place.
And, how do I programmatically obtain the necessary information about smtp on a computer in a corporate network?
As I said in my previous message, you *could* scan the local LAN to see if any machine has an open port 25. This can be considered unfriendly behavior, though, and you should probably ask the user permission before beginning a scan.
Another slightly sneaky way to do it would be to test all hostnames that are in the local machine's DNS cache. If the user has been using email lately, chances are his mail server will appear there. Shell out to the commandline
IPCONFIG /DISPLAYDNS
and capture the results to a file. Go through the result file and extract the host names from lines which contain the words "Record Name".
If you turn up empty, prompt the user to check his email or send a test email, and try again.
BTW -- I'm sure you're a good guy and all...but just to be sure, please
assure us that you're not writing a spambot.
joe215 wrote: I want my users to send emails from a Windows app that I am developing in Visual Basic.NET 2003. I found a good example of sending email to a SMTP server using the SmtpMail class. However, using this, it seems, that the user must install IIS on their computer. Isn't there a class that will detect whatever mail server is available on a computer and use that? How do I create this functionality without having the user add any other programs or change any previously defined configurations - just use their computer's email system?
Thanks, joe
No, no! This is legit. The program is a data logger and will send an alarm
email message to a building supervisor if the data logging stops for some
reason.
-Joe
"John A. Bailo" wrote: BTW -- I'm sure you're a good guy and all...but just to be sure, please assure us that you're not writing a spambot.
joe215 wrote: I want my users to send emails from a Windows app that I am developing in Visual Basic.NET 2003. I found a good example of sending email to a SMTP server using the SmtpMail class. However, using this, it seems, that the user must install IIS on their computer. Isn't there a class that will detect whatever mail server is available on a computer and use that? How do I create this functionality without having the user add any other programs or change any previously defined configurations - just use their computer's email system?
Thanks, joe This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: David |
last post by:
I'm wondering if python is capable of fairly precise timing and also sending
data out the parallel port.
For example ; making a 7.5 KHz square wave come out of one of the data pins
on the...
|
by: Mr. x |
last post by:
Hello,
I am sending emails with Hebrew contents.
When receiving emails - I cannot see the Hebrew characters (it is not
outlook express configuration, because when receiving emails from friends -...
|
by: festivalman |
last post by:
Hi, sorry if this is in the wrong spot. Finding the newsgroups on MS's site could have been easier
Here's my problem
I've got some old asp's that are running our simple web site. In a section,...
|
by: joe215 |
last post by:
I want my users to send emails from a Windows app that I am developing in
Visual Basic.NET 2003. I found a good example of sending email to a SMTP
server using the SmtpMail class. However, using...
|
by: Ant |
last post by:
Hi, I'm using the MailMessage & smtpMail classes in System.Web.Mail to send
mail, however it's not sending any emails.
I'm using it on a Windows 2003 server.
The simplest way to use this is...
|
by: Eric Sheu |
last post by:
Greetings,
I have been searching the web like mad for a solution to my SMTP problem. I
am using Windows Server 2003 and ASP.NET 2.0 w/ C# to send out e-mails from a
web site I have created to...
|
by: armando perez |
last post by:
Hi, this is my first time here, but I was looking for something that
may help me, and still, I haven't found something to use.
I'm using a website made in .NET with C#, when I'm running my site...
|
by: xin.yadong |
last post by:
Hi:
I have a shared function for sending Email using SMTP.
It works fine in a ASP.NET web application. But when I use it in a
VB.Net Windows application, it always gave me an error: "Could not...
|
by: happyse27 |
last post by:
Hi All,
I am trying for weeks how to send email from windows pc, which from my gmail account to my hotmail account. Using net::smtp module sending email failed,Kindly assist. (for the item d it...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |