Sending Email

Mike Bailey

Regular
Joined
Sep 26, 2003
Messages
57
Location
Renton, WA
I’m a student studding the DOT Net framework we are currently working in V.B.

I would like to build a program that will send an email with an attachment (like a picture) can anyone get me started in the right direction.

I don’t know if you can send email directly from a V.B program or if I must link to Outlook?

Can someone tell me where to find the commands and the Syntax.

Thanks for any help
 
Sending email is a nice feature in .NET.

First you'll 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 can't 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’s going to do is take a picture of the user (
With a webcam) and email that to anyone the user specifies.

I t will work a lot like the one at the Microsoft Museum if you have ever seen that one. I probably could have just got that one but then I wouldn’t have learned anything and that is what this is all about. I’m not making any money just a project for School.

Thanks for any additional halp
 
Last edited:
If you don't 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 I'm getting this


The messeage comes when it runs the last line of code

Hers my code

Visual Basic:
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

Visual Basic:
An unhandled exception of type 'System.Web.HttpException' occurred in system.web.dll

Additional information: Could not access 'CDO.Message' object.
 
Last edited:
Add a line jsut before you send the email, I don't 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 you're receiving is a roundabout way of saying you don't 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