By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,686 Members | 1,558 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,686 IT Pros & Developers. It's quick & easy.

Send Email with Attachment Using vb

P: 2
Any1 can tell me how to go about sending email with attachment in vb programming code. I know SMTP is one option, but I can't seem to get it working. Any other suggestion??

Thanks in advance
Oct 3 '08 #1
Share this Question
Share on Google+
4 Replies


100+
P: 283
smtp as you stated is one option but depending on who your end users are you can also use the office inerop components

I will have a look later and try to find / work out some working email code for the smtp , I believe that you have to send the email as html and convert the file to a mime encodement somehow.
Oct 3 '08 #2

P: 2
smtp as you stated is one option but depending on who your end users are you can also use the office inerop components

I will have a look later and try to find / work out some working email code for the smtp , I believe that you have to send the email as html and convert the file to a mime encodement somehow.
here is my code( i got 3 sets of code) , but all 3 is not working, and i don't know where went wrong, Please Help! Thanks in advance

'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''
'Web.Mail.SmtpMail.SmtpServer = "user1"
'Dim msg As New Web.Mail.MailMessage

'msg.From = "weijie@admin"
'msg.To = "weijie1412@hotmail.com"
'msg.Subject = "testing"
'msg.Body = "hello first email"
'msg.BodyFormat = Web.Mail.MailFormat.Text

'Web.Mail.SmtpMail.Send(msg)

'MsgBox("Yea")
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''
'Dim msg As System.Web.Mail.MailMessage
'Dim smtp As System.Web.Mail.SmtpMail
'Dim att As System.Web.Mail.MailAttachment

'msg.To = "weijie1412@hotmail.com"
'msg.From = "weijie1412@gmail.com"
'msg.BodyFormat = MailFormat.Text
'msg.Body = " testing, Please work pls "
'msg.Cc = " Cc: Testing, Please Work "
'msg.Subject = "Testing purpose"


'smtp.Send(msg)

'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''''
'Dim message As System.Net.Mail.MailMessage
'Dim smtp As New System.Net.Mail.SmtpClient("smtp.gmail.com", 587)

''Dim attach As System.Net.Mail.Attachment
'Dim sFrom As String, sTo As String, sSsub As String, sMsg As String
''Dim sFile As String

'sFrom = "user1.edel@gmail.com"
'sTo = "weijie1412@hotmail.com"
''sFile = "D:\\j\\j5\\h\\tgk\\net\\eml1\\e2\\emlcmds.txt "
'sSsub = "t w"
'sMsg = "a"

'message = New System.Net.Mail.MailMessage(sFrom, sTo, sSsub, sMsg)

''If My.Computer.FileSystem.FileExists(sFile) Then
'' attach = New System.Net.Mail.Attachment(sFile)
'' message.Attachments.Add(attach)
''End If

'smtp.EnableSsl = True
'smtp.Credentials = New System.Net.NetworkCredential("user1.edel@gmail.com ", "pwd")

'Try
' smtp.Send(message)
' Console.WriteLine("Sent")
'Catch exc As Net.Mail.SmtpException
' Console.WriteLine(exc.StatusCode.ToString)
'End Try

'tbxEmail.Text = ""

'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''
Oct 7 '08 #3

100+
P: 283
if I have a chance I will look through the code and try to see what is wrong but meanwhile try looking at this tutorial -

http://www.codeproject.com/KB/vb/SendMail.aspx
Oct 7 '08 #4

P: 77
Hi

THis is the easy way to do that. Put this code insite a Buttom Click event

[code]

Dim mySmtp As New System.Net.Mail.SmtpClient
mySmtp.Host = "192.168.2.1" 'or your correct smtp server name i.e. "smtp.terra.com"
Try
mySmtp.Send("rpicilli@terra.com.br", "toyou@docstibrasil.com.br", "Teste com .NET", "Hi there")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

/[code]


I hope this help
Oct 8 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.