Sending Email

Sending email is a nice feature in .NET.

First youll want to add a reference to system.web.mail.

then add some code simliar to this:

Code:
Dim objEmailMessage As System.Web.Mail.MailMessage
        Dim objSMTPServer As System.Web.Mail.SmtpMail

        objEmailMessage = New System.Web.Mail.MailMessage
        With objEmailMessage
            .To = "me@mydomain.com"
            .From = "bill.gates@microsoft.com"
            .Subject = "Great Job!"
            .Body = "Want all my money?"
        End With

        objSMTPServer.Send(objEmailMessage)

You can specify a specific SMTP server if required, and you can add attachments using the attachments property.

This should give you a good enough start.

Sam.
 
Mike is this a Windows app? If so then you cant use System.Web.Mail

Actually adding a ref to SystemWeb.dll might work.
 
Yes system.web WILL work in a Windows application. Its jsut a namespace.

2ndly, goto the references, right click and select add a new reference, and then find system.web.

Then you can do everything.
 
Yep tryed it and it works THANKS ALOT.
In the code above I dont see a way to add a smtp server. Is it useing seting already on the computer or what?
 
Thanks everyone for all the help I have worked on this and everything is working fine I will need to modify the code provided by (samsmithnz) (Tanks by the way) But it seems to work just like it is. When I run it I see my outgoing email scanner go off but I never receive an email I changed the code to my email address but still get nothing. The only thing I can think of is that I have specified an SMTP server. Can anyone help???
 
no and I will be puting this program on another machine so I really need to be abel to specafy the smtp server.

I really need to beable to use a smtp sever like comcast

(smtp.comcast.net)

This project is for the Museum of Flight In Seattle what it
 
Last edited by a moderator:
If you dont have a SMTP server on the client computer then what you could do is maybe set up an email hosting/website hosting and use the server name that would be provided. Like email.yourdmain.com. Works for me with the email server provided by my webhost.
 
Now Im getting this


The messeage comes when it runs the last line of code

Hers my code

Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim objEmailMessage As System.Web.Mail.MailMessage
        Dim objSMTPServer As System.Web.Mail.SmtpMail

        objEmailMessage = New System.Web.Mail.MailMessage
        With objEmailMessage
            .To = txtToEmail.Text
            .From = txtFrom.Text
            .Subject = "Great Job!"
            .Body = "Want all my money?"
        End With

       [color=red] objSMTPServer.Send(objEmailMessage)[/color]


   
    End Sub
End Class
When the code that is in red is ran I get this error

Code:
An unhandled exception of type System.Web.HttpException occurred in system.web.dll

Additional information: Could not access CDO.Message object.
 
Last edited by a moderator:
Add a line jsut before you send the email, I dont have VS.NEt open right here, but if you type in objSMTPServer and then a dot, you can select a STMPSERVER property (or something like that), and add "smtp.comcast.com".

That error youre receiving is a roundabout way of saying you dont have smtp confgiured on your computer. I recommend you select MailMessage and SmtpMail in your code and press F1 to get an overview of what each class actually does.

Sam
 
Back
Top