VB.Net 2008 Send Email Help Needed

VB.Net 2008 Send Email Help Needed

Page 1 of 1

2 Replies - 1442 Views - Last Post: 20 November 2010 - 08:11 PM Rate Topic: -----

#1 redleg  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 20-November 10

VB.Net 2008 Send Email Help Needed

Posted 20 November 2010 - 04:53 AM

Trying to send email from inside my application. Have traced everything in the program and everything appears fine.

Connection is made to my smtp server (shown in log files) but the message is never sent. Is there something wrong with my code or is it something else????????


    Private Sub sendAsEmailButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sendAsEmailButton.Click

        Dim form As New EmailData()
        form.ShowDialog()

        Dim toaddress = form.toAddressTextBox.Text
        Dim ccaddress = form.ccAddressTextBox.Text

        Try

            Dim msg As New MailMessage()
            msg.From = New MailAddress("my@email.com")
            msg.To.Add(toaddress)
            If Not ccaddress = "" Then
                msg.CC.Add(ccaddress)
            End If

            msg.Subject = "forced message title"
            msg.IsBodyHtml = False
            msg.Body = BuildMessage() 'returns message body as string
         
            Dim smtp As New SmtpClient("mail.mysmtpserver.com")
            smtp.Port = 25
            smtp.Credentials = New System.Net.NetworkCredential("myuaername", "mypassword")
            smtp.Send(msg)

        Catch ex As Exception
            
        End Try
    End Sub


This post has been edited by redleg: 20 November 2010 - 04:55 AM


Is This A Good Question/Topic? 0
  • +

Replies To: VB.Net 2008 Send Email Help Needed

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: VB.Net 2008 Send Email Help Needed

Posted 20 November 2010 - 05:53 AM

Depending on your email host, you might need to try a different port
Here's a post with a working version using hotmail. I'm pretty sure it works with gmail (changing the smtp client of course)

http://www.dreaminco...post__p__991796
Was This Post Helpful? 0
  • +
  • -

#3 Guest_redleg*


Reputation:

Re: VB.Net 2008 Send Email Help Needed

Posted 20 November 2010 - 08:11 PM

Found the problem with it. Had to add a line:


        msg.From = New MailAddress("my@email.com")  
        msg.Sender = msgFrom      ' this line added
        msg.To.Add(toaddress)  

 



Works like a charm now....
Was This Post Helpful? 0

Page 1 of 1