Page 1 of 1

Mail program help

Posted: Sat Nov 24, 2012 7:17 pm
by muttley1968
Hello i am currently buildling an application that uses gmail and on the computer it is built on no problems at all work fine not a single error but the second i run it on ANY other computer weather i am loged into that gmail account or not i get this error

Image

I really need to get this fixed as it is the last known issue in my program and then its just working on graphics and it will be finished.

Re: Mail program help

Posted: Sat Nov 24, 2012 8:12 pm
by pip
What is code for line 25 of form1 and is it a button click? the problem is with that line it looks like from error. @ #muttley1968
I don't know if i can help but i am willing to try :D

Re: Mail program help

Posted: Sat Nov 24, 2012 10:29 pm
by muttley1968
This is the code for the hole button of which the
mail.send section is line 25 of my code
only diffrence between this code and my program is that i have removed my pass and put it to 12345 so you dont know my actaull password
Code: Select all
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim SmtpServer As New SmtpClient()
            Dim mail As New MailMessage()
            SmtpServer.Credentials = New  _
  Net.NetworkCredential("xprograming.manning516@gmail.com", "12345")
            SmtpServer.Port = 587
            SmtpServer.Host = "smtp.gmail.com"
            mail = New MailMessage()
            mail.From = New MailAddress(TextBox2.Text)
            mail.To.Add("xprograming@gmx.co.uk")
            mail.Subject = "Test Mail"
            mail.Body = ((Label1.Text + TextBox1.Text) & vbCrLf & (Label2.Text + TextBox2.Text) & vbCrLf & (Label3.Text + TextBox3.Text) & vbCrLf & (Label4.Text + TextBox4.Text))
            PictureBox3.Image.Save(ms, ImageFormat.Png)
            ms.Position = 0
            mail.Attachments.Add(a)
            SmtpServer.Send(mail)
            MsgBox("mail sent")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

Re: Mail program help

Posted: Sun Nov 25, 2012 2:26 am
by Scottie1972
try to add
Code: Select all

Mail.EnableSsl = True

to your code since you are using Gmail.com

example:
Code: Select all
Imports System.Net.Mail

'Start by creating a mail message object
Dim MyMailMessage As New MailMessage()

'From requires an instance of the MailAddress type
MyMailMessage.From = New MailAddress("from_address_here@gmail.com")

'To is a collection of MailAddress types
MyMailMessage.To.Add("to_address_here@domain_name_here")

MyMailMessage.Subject = "GMail Test"
MyMailMessage.Body = "This is the test text for Gmail email"

'Create the SMTPClient object and specify the SMTP GMail server
Dim SMTPServer As New SmtpClient("smtp.gmail.com")
SMTPServer.Port = 587
SMTPServer.Credentials = New System.Net.NetworkCredential("account uid", " account pwd")
SMTPServer.EnableSsl = True

Try
   SMTPServer.Send(MyMailMessage)
   MessageBox.Show("Email Sent")
Catch ex As SmtpException
   MessageBox.Show(ex.Message)
End Try
Refference Link:
http://geekswithblogs.net/TakeNote/arch ... 13974.aspx

Re: Mail program help

Posted: Sun Nov 25, 2012 2:28 am
by CodenStuff
You may be missing SSL because I remember gmail being a rite pain for sending mail. Try adding this within the code:
Code: Select all
SmtpServer.EnableSsl = true
I think thats what it was :?

P.S. Scottie beat me to it while I was typing out my reply :lol:

Re: Mail program help

Posted: Sun Nov 25, 2012 2:27 pm
by muttley1968
thanks everyone that seems to have done the trick its a tab bit slow but ill just add a progressbar so people know it hasnt frozen