Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Im creating an email sender with attachment in my program using vb.net. SMPT Server PORT, SSL, HOST and IsBodyHtml values in the comboboxes|textboxes cannot be read during the sending process. Im still new in this language, can anyone help me with my codes.?! Here's my screen shot of the program https://fbcdn-sphotos-c-a.akamaihd.net/hphotos-ak-prn2/1450048_755648697783890_582817513_n.jpg[^] .

VB
Imports System.Net.Mail

Public Class sendmail

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Try


            Dim Smtp_Server As New SmtpClient
            Dim e_mail As New MailMessage()
            Dim attachment As System.Net.Mail.Attachment

            Smtp_Server.UseDefaultCredentials = False
            Smtp_Server.Credentials = New Net.NetworkCredential((txtuser.Text), (txtpass.Text))


            'sending failure
            Smtp_Server.Port = txtserport.Text 'cannot be read
            Smtp_Server.EnableSsl = cboserenssl.Text 'cannot be read
            Smtp_Server.Host = cboserhost.Text 'cannot be read
           
            e_mail = New MailMessage()
            e_mail.From = New MailAddress(txtfrom.Text)
            e_mail.To.Add(txtto.Text)
            e_mail.Subject = txtsubject.Text
           e_mail.IsBodyHtml = cbohtmlbody.Text 'cannot be read
            e_mail.IsBodyHtml = cbohtmlbody.Text
            e_mail.Body = txtbody.Text


            'this line here excute correctly but if a user didd'nt attach  a file, sending fails..
            'i want to send even w/o an attach file..
            attachment = New System.Net.Mail.Attachment(txtattach.Text) 'file path
            e_mail.Attachments.Add(attachment) 'attachment

           

            Smtp_Server.Send(e_mail)
            txtmailstat.Text = "Successfully send" ' if it fails to send, how to?



        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub
Posted
Updated 28-Nov-19 19:57pm
v3
Comments
bbirajdar 6-Nov-13 4:24am    
Since you did not receive any solution for your question in 22 hours, I suggest you to make these changes to the question-

1.
2. Paste the exact error message. "cannot execute properly" does not make any sense to us. Can you guide some person who just says his code "cannot execute properly " ??????
akosisugar 6-Nov-13 4:38am    
sori.. the error is.> SMPT Server PORT, SSL, HOST and IsBodyHtml values in the comboboxes|textboxes cannot be read during the sending process.

1 solution

Try this fix-

VB
 attachment = New System.Net.Mail.Attachment(txtattach.Text) 'file path
if(attachment <> null)
            e_mail.Attachments.Add(attachment) 'attachment


Edit-

You are assigning a Text value to the Boolean property. So convert the text to Boolen first

e_mail.IsBodyHtml = cbohtmlbody.Text 'cannot be read

should be

e_mail.IsBodyHtml = Convert.ToBoolean(cbohtmlbody.Text) 'cannot be read

Same for other errors too..

Similarly
Smtp_Server.Host = cboserhost.Text 'cannot be read

Should be

Smtp_Server.Host = cboserhost.SelectedItem.Text 'cannot be read


And do not jump into programming without learning the basics
 
Share this answer
 
v3
Comments
akosisugar 6-Nov-13 5:21am    
(attachment <> null)

'null' is not declared. 'Null' constant is no longer supported; use 'System.DBNull' instead.
bbirajdar 6-Nov-13 6:05am    
The error is self explanatory.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900