Dynamically Sending Emails

John-Boy1

Member
Joined
Mar 6, 2006
Messages
14
Programming Experience
Beginner
I have created a IP Thermostat programme in VB.NET

I want to get it to dynamically send an e-mail message from the server to the user e-mail address when the temperature change has been confirmed.

Do i have to link the programme to Outlook?

Any help will be appreciated as extremely clueless at present on this subject.

Thanks
 
SmtpMail class in System.Web.Mail namespace has got the Send Method.
Here is the code from documentation:
VB.NET:
Dim myMail As New MailMessage
myMail.From = "from@microsoft.com"
myMail.To = "to@microsoft.com"
myMail.Subject = "UtilMailMessage001"
myMail.Priority = MailPriority.Low
myMail.BodyFormat = MailFormat.Html
myMail.Body = "<html><body>UtilMailMessage001 - success</body></html>"
Dim myAttachment As New MailAttachment("c:\attach\attach1.txt", MailEncoding.Base64)
myMail.Attachments.Add(myAttachment)
SmtpMail.SmtpServer = "smtpserver"
SmtpMail.Send(myMail)
 
Many Thanks John,

This may sound like a stupid question but do i need to set the smtp server up? if so how do i set up a smtp server? Is this software i need to install? Or can i connect to an external smtp server?

Sorry for the quantity of questions
 
Not unless you want to.. :) You normally use the Smtp server of your ISP, the same used when sending regular emails from your internet account.
If host this in a webserver and got Smtp server also, you can use the Smtp server address 'localhost'.

But I forgot to mention that to use the code you have to Add Reference to the System.Web.dll and Imports System.Web.Mail (or fully qualify the objects that belong in this namespace)

Here is some info on authentication, should you need it http://www.dotnetrooms.com/showthread.php?t=23
 
Think creating a Smtp may be a little beyond my ;)

Just to clarify if i want to use my ISP Smtp server (for example Outlook) the server address will be just 'localhost'.

No need for IP addresses etc?
 
Depends on what context, if this is ASP.Net page on online webserver maybe the provider has got a Smtp server on the same server that is available as 'localhost', but if we are thinking home user then the ISPs address is typically 'smtp.provider.com'
 
I have a problem with adding the namespace System.Web.Mail

At present the only options i have under system.web is asp hosting permission.

The current programme has been developed to be a desktop application for the home user.
 
JohnH said:
...you have to Add Reference to the System.Web.dll
Do this like adding any other extra libraries, in Solution Explorer rightclick References to get context menu, click Add Reference. System.Web.dll is in .Net page in that dialog. You can also do it from Project manimenu choice.
 
Just be awared of what e-mails YOU send and to whom? Ones your emails are reported as a spams you'll be reported to your ISP as spammer and sooner or later they will cancel the service to you. It is valid for the web sites as well (your app will be removed by the host company if you've been reported as spammer). I know that you may think that this doesn't Corresponding very much with your question but, please notice that I do not blame you. All i want is to warn you cuz these are things you need know before you involve yourself in something that may bring troubles for you.
Regards ;)
 
Many thanks for your concerns.

But the project im building is just for personal use and wouldn't involve sending e-mails to "unknowns".

Much appreciation to both of you for your help
 
I am trying to do something similar, but have an issue with the localhost

Sub button_click()

Dim emailfrom As String = "myaddress@hotmail.com"
Dim emailto As String = "myaddress@mosaic.net.nz"
Dim emailsubject As String = "Important message"
Dim emailbody As String = "Thanks for reading this"

Dim mysmtpclient As New System.Net.Mail.SmtpClient("localhost")
mysmtpclient.send(emailfrom, emailto, emailsubject, emailbody)

End Sub
 
Do you have an Smtp server installed at the machine running the code, CookieNZ?
 
Back
Top