VB Net 2005 and Email!

T

Tull Clancey

Hi all.

Having spent some time trying to get .net 2003 to send emails I'm now
struggling with the 2005 version of smpt.

Microsoft seem to have changed their view on the smtp side of things, before
they gave a single error message for absolutely everything, now I'm getting
no error message, but nothing gets sent!

Can anyone tell me why the following isn't doing anything? I get my final
message box, but no mail is sent!

Thanks,
Tull.

Dim fromAddress As New MailAddress([email protected], "Info")
Dim toAddress As New MailAddress([email protected], "Tull")

Dim msg As New MailMessage(fromAddress, toAddress)

msg.Body = "This is a test of a mail message from VB Net 2005!"
msg.Subject = "Testing new email, sent at " &
DateTime.Now.ToString()
msg.IsBodyHtml = True

Dim mailSender As New System.Net.Mail.SmtpClient()
mailSender.Host = "smtp.myserver.co.uk"

Try
mailSender.Send(msg)
Catch ex As Exception
MsgBox(ex.ToString)
End Try

MsgBox("Mail sent")
 
G

Guest

Here is what I use and it does work.

' SMTP Mail Service
Dim smtpclient As New SmtpClient
Dim msg As New MailMessage
msg.To.Add(strMailTo.Replace(";", ","))
msg.From = New MailAddress(strMailFrom)
msg.Subject = strMailSubject
msg.IsBodyHtml = True

Dim FileName As String
FileName = Guid.NewGuid().ToString() + ".gif"
Dim fs As New FileStream("C:\Export\" + FileName, FileMode.CreateNew)
Dim writer As New BinaryWriter(fs)
writer.Write(Attachment)
writer.Flush()
writer.Close()

msg.Attachments.Add(New Attachment("C:\Export\" + FileName))
msg.Body = "<img border='0' src= " & FileName & " width='579' height='751'>"

smtpclient.Host = "mail.hostserver.com"
smtpclient.Send(msg)
msg = Nothing

File.Delete(FileName)

Hope this helps

Brian
 
J

Jay B. Harlow [MVP - Outlook]

Tull,
In addition to the other comments.

For .NET 1.x SMTP questions see:

http://www.systemwebmail.com/

For .NET 2.0 SMTP questions see:

http://www.systemnetmail.com/

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| Hi all.
|
| Having spent some time trying to get .net 2003 to send emails I'm now
| struggling with the 2005 version of smpt.
|
| Microsoft seem to have changed their view on the smtp side of things,
before
| they gave a single error message for absolutely everything, now I'm
getting
| no error message, but nothing gets sent!
|
| Can anyone tell me why the following isn't doing anything? I get my final
| message box, but no mail is sent!
|
| Thanks,
| Tull.
|
| Dim fromAddress As New MailAddress([email protected], "Info")
| Dim toAddress As New MailAddress([email protected], "Tull")
|
| Dim msg As New MailMessage(fromAddress, toAddress)
|
| msg.Body = "This is a test of a mail message from VB Net 2005!"
| msg.Subject = "Testing new email, sent at " &
| DateTime.Now.ToString()
| msg.IsBodyHtml = True
|
| Dim mailSender As New System.Net.Mail.SmtpClient()
| mailSender.Host = "smtp.myserver.co.uk"
|
| Try
| mailSender.Send(msg)
| Catch ex As Exception
| MsgBox(ex.ToString)
| End Try
|
| MsgBox("Mail sent")
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top