Print and Email Screen....

sohaib

Well-known member
Joined
Apr 30, 2005
Messages
64
Programming Experience
3-5
Hi guys!!


I have a little bit problem regarding printing forms and email file...

I have made an entry form i want to send it with email and print its form (or any file we can say) as well ...Can it b possible in VB.Net.....


Actually, We have clients which can b contacted with us by email or by hand so we want a form in this way that after entering above general information and the rest of the information should be entered by a person own so for this case we have to send it to them by email or by hand in the form of print...

I have already found a code related to attaching file for emailing directly from the pgm but imports system.Web.mail is not recognized by my system...Can anyone help me about this....

Can anyone plz help me in this regard..

Hope for the positive response from u people soon...

If any good suggestion to solve this problem i will really appreciate to u.

ok Bye
 
Hi!!

Nice to hear from you....Can you please tell me how i can add a reference...I m not able to make this thing happen so please Let me know that how i can make it easy for myself...

Hope for the positive response from you soon...

Ok

Bye...
 
Hi jimhilnney!!

It's really nice and i learn to know about add references anyway...but when i m trying to send mail then here is an email error....

"CDO.Message" error...

I can't understand wht does it means....

Can u help me in this regard...

Ok. Thnx a lot for reply

Bye...
 
I think you need to post the section of code where the error occurs and point out the actual line that causes the error. Also, what exactly is the error message that you get? Even the best doctor has to get some information from their patient to be able to make a diagnosis.
 
Hi jmchilhinney!!

You are absolutely right to say that doctor should b aware of the details about the patients......anyways...I m sending u code details....n i hope u will understand and help me in this regard or any other corrected code or advice it will b really helpful to me...


Here is the Code......
Imports System.Web.Mail

PublicClass ViewReportsfrm

Inherits System.Windows.Forms.Form

' Remove Attachment

PrivateSub bttnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnRemove.Click

If lstAttachment.SelectedIndex > -1 Then

lstAttachment.Items.RemoveAt(lstAttachment.SelectedIndex)

EndIf

EndSub

' Send Mail

PrivateSub bttnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnSend.Click

Dim Counter AsInteger = 0

Dim strError AsString = ""

If txtSMTPServer.Text.Trim() = "" Then

MessageBox.Show("Enter your SMTP server.", "Email Error", MessageBoxButtons.OK, _

MessageBoxIcon.Stop)

txtSMTPServer.Focus()

Return

EndIf

If txtFrom.Text.Trim() = "" Then

MessageBox.Show("Enter the From address.", "Email Error", MessageBoxButtons.OK, _

MessageBoxIcon.Stop)

txtFrom.Focus()

ExitSub

EndIf

If txtTo.Text = "" Then

MessageBox.Show("Enter the Recipient address(es).", "Email Error", _

MessageBoxButtons.OK, MessageBoxIcon.Stop)

txtTo.Focus()

ExitSub

EndIf

If txtSubject.Text = "" Then

MessageBox.Show("Enter the subject.", "Email Error", MessageBoxButtons.OK, _

MessageBoxIcon.Stop)

txtSubject.Focus()

ExitSub

EndIf

Try

Dim objSmtpMail As System.Web.Mail.SmtpMail

Dim Attachment As System.Web.Mail.MailAttachment

Dim Mailmsg AsNew System.Web.Mail.MailMessage

objSmtpMail.SmtpServer = txtSMTPServer.Text.Trim()

Mailmsg.To = txtTo.Text

Mailmsg.Cc = txtCC.Text

Mailmsg.Bcc = txtBCC.Text

Mailmsg.Subject = txtSubject.Text

Mailmsg.Body = txtMessage.Text

Mailmsg.Headers.Add("Reply-To", txtReplyto.Text)

Mailmsg.Headers.Add("X-Organization", txtOrganization.Text)

Mailmsg.From = "\" & txtDisplayName.Text & "\ <" & txtFrom.Text & ">"

If chkFormat.Checked = TrueThen

Mailmsg.BodyFormat = MailFormat.Html

Else

Mailmsg.BodyFormat = MailFormat.Text

EndIf

IfMe.radHigh.Checked Then

Mailmsg.Priority = MailPriority.High

ElseIfMe.radLow.Checked Then

Mailmsg.Priority = MailPriority.Low

Else

Mailmsg.Priority = MailPriority.Normal

EndIf

For Counter = 0 To lstAttachment.Items.Count - 1

Attachment =
New MailAttachment(lstAttachment.Items(Counter).ToString)

Mailmsg.Attachments.Add(Attachment)

Next

objSmtpMail.Send(Mailmsg)

Catch ex As Exception

MessageBox.Show(ex.Message, "Email Error", MessageBoxButtons.OK, _

MessageBoxIcon.Stop)

EndTry

EndSub

' Attach Files

PrivateSub bttnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnAdd.Click

Dim Counter AsInteger

Ofd.CheckFileExists = True

Ofd.Title = "Select the file(s) to attach"

Ofd.ShowDialog()

For Counter = 0 To UBound(Ofd.FileNames)

lstAttachment.Items.Add(Ofd.FileNames(Counter))

Next

EndSub

End
Class


Email Error.....

Could not access 'CDO.Message' Object.
 
I don't know whether this is what's causing your error or not but SmtpServer and Send are Shared members of the SmtpMail class. You don't need to declare a variable of type SmtpMail, which you fail to instantiate anyway. For Shared members you simply use the class name, e.g. SmtpMail.SmtpServer or SmtpMail.Send(myMessage). No actual SmtpMail object required or desired. Change that and see what happens.
 
Hi!!

It's reallly good tht i got ur reply very soon...but i haven't get it the right output uptill now it gives another error ....It's not working....I think so u r right in that sense but when i m trying to use smtpmail.send(From,to,Subject,message) or smtpmail.smtpserver(message) In both of the cases it's not working....

Can u guide me....with giving me a right code..

Ok

Bye

n thnx a lot
 
The line that reads:

Dim objSmtpMail As System.Web.Mail.SmtpMail

should be removed. Once you do that you'll get a couple of errors saying that objSmtpMail doesn't exist. On those lines, just remove the "obj" prefix and then try.

 
Hi Again!!

U r right enough that removing obj i m able to run the program right now but it's still giving the same error.....

" Email Error"
Could not access CDO.Message.....

If u have any idea right now so plz help me..

Ok Bye
 
Last edited:
I tend not to use chat programs. I'm at my work machine pretty much all day so I'll get notification of a post within 15 minutes.

You should use the tried and tested debugging method of going back to basics. Try sending a message by hardcoding adresses and servers that you know are vaild. Don't add headers or attachments. Use just an address in the From field. Just the essential stuff, and then when it works you add the other bits one by one until it stops working. Now you know where the issue is you can deal with that issue specifically.

Also, it's not a problem but the reason you import a namespace is so that you don't have to qualify all your classes. If are going to declare a variable as being of type System.Web.Mail.MailMessage, rather than just MailMessage, then there is not much point importing the System.Web.Mail namespace. Many people recommend that you do fully qualify when using unfamiliar namespaces. This is a good idea but it is best not to import in this case because it forces you to be consistent.

Edit:
I'd suggest that you don't post your instant messaging ID or e-mail address so publicly unless you like spam.
 
yes Sir!!

U r right....I m using only mail address for sending mail ...i m not attaching any file right now....

or i will do again from the basics......Now, i will send u post as u r not tend to use chat programs....

Ok i will try and then tell you but the error is still there....anyways...

i have alread edit my last message...ok

thnx again..

ok bye
 
Hi Sir!!

I just write what you have given me to do....but still i m not getting my output right....

If u dont mind to tell about how i can do in an easy way...

Hope for the positive response from you...


ok

Bye
 
There is an example of sending an e-mail message here. Follow the example to get the mechanism working, then add things like attachments and headers bit by bit until you either strike an issue or get the whole thing working.
 
Back
Top