Mike Bailey Posted December 19, 2003 Posted December 19, 2003 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 Quote
samsmithnz Posted December 19, 2003 Posted December 19, 2003 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: 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. Quote Thanks Sam http://www.samsmith.co.nz
Mike Bailey Posted December 19, 2003 Author Posted December 19, 2003 Thank you very much but what do you mean by. (First you'll want to add a reference to system.web.mail.) Quote
Moderators Robby Posted December 19, 2003 Moderators Posted December 19, 2003 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. Quote Visit...Bassic Software
Mike Bailey Posted December 19, 2003 Author Posted December 19, 2003 Yes this is a Windows App but I don't understand what adding a ref to SustmeWeb.dll means Quote
samsmithnz Posted December 19, 2003 Posted December 19, 2003 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. Quote Thanks Sam http://www.samsmith.co.nz
Mike Bailey Posted December 19, 2003 Author Posted December 19, 2003 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? Quote
Mike Bailey Posted December 19, 2003 Author Posted December 19, 2003 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??? Quote
Moderators Robby Posted December 19, 2003 Moderators Posted December 19, 2003 Is the SMTP configured on your machine? Quote Visit...Bassic Software
Mike Bailey Posted December 19, 2003 Author Posted December 19, 2003 (edited) 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 Edited December 19, 2003 by Mike Bailey Quote
*Experts* mutant Posted December 19, 2003 *Experts* Posted December 19, 2003 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. Quote
Mike Bailey Posted December 20, 2003 Author Posted December 20, 2003 (edited) Now I'm getting this The messeage comes when it runs the last line of code Hers my 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 An unhandled exception of type 'System.Web.HttpException' occurred in system.web.dll Additional information: Could not access 'CDO.Message' object. Edited December 20, 2003 by Mike Bailey Quote
samsmithnz Posted December 20, 2003 Posted December 20, 2003 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 Quote Thanks Sam http://www.samsmith.co.nz
darknuke Posted December 21, 2003 Posted December 21, 2003 objSMTPServer.smtpserver = "smtp.comcast.net" :) Quote This is only a test of the emergency broadcast system This is a product of hysterical mass confusion A ship of fools adrift on the sea of our pollution Rudderless and powerless on the sea of our delusion pennywise - this is only a test
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.