|
|
How To Send Email Using VB (using SMTP) ? - best way to send email in vb | ||
Discussion by connectpal with 16 Replies.
Last Update: June 13, 2011, 5:45 am ( View Rated (6) ) | |||
![]() |
|
|
I want to send an email to multi users through my VB application.
I don't know if I can use a VB class for this case or I should download a smtp mail component.
I would be thankful if you can suggest me the best solution.
Please give me a code example for former solution or introduce me an effective free, permanent component.
And also, you might want to consider posting this in the Visual Basic forum.
But you do need a SMTP server where you have a account from, like the smtp server of your isp since relaying is disabled in 99 out of 100 servers these days
I did create a small basic smtp email proggie though, if you need the VB source i might even mail it to you if you ask nicely
The .NET framework provides you with a class called SmtpMail - which under normal circumstances isn't available for use with Windows forms. It's meant for ASP.NET applications and can be found in the library System.Web.Mail namespace. All you've to do to make it work in your WinForm application is include a Reference to the file, System.Web.dll. This can be done by right-clicking on References in your Project explorer and clicking Add reference.
Once you've added this, use the following code to send mails out:
CODE
Imports System;Imports System.Web.Mail;
Dim EmailTo As String 'Emailaddres for user to send
Dim EmailFrom As String 'Emailaddres for user from
Dim MailSubject As String 'Subject of Mail
Dim MessageBody As String 'Message
Dim ServerName As String 'Server Name - important
ServerName = "<<Your SMTP server's Name>>"
'Similarly, add in EmailTo, EmailFrom etc parameters here
EmailTo = "someone@recipient.net"
EmailFrom = "me@mysqlf.net"
...
.....
'Set the SMTP Server's address
SmtpMail.SmtpServer = ServerName
'This is the code that sends out the email based on whatever server information you've set
'Enclosed within Try-Catch block to catch exceptions in case of errors
Try
SmtpMail.Send (EmailFrom, EmailTo, MailSubject, MessageBody)
Catch ex As Exception
MsgBox ( "Delivery Failure: " & ex.Source & ex.Message )
End Try
Hope this helps...
Regards,
m^e
How To Send Email Using VB (using SMTP) ?
I have to simple coding in email sending.I have use To,From,Subject, Message and Submit Button...When I send mail it will be store in my computer..I have use ASP.net with VB,VB.NET.
-reply by chitar bahadur
Sub SendMail()
Dim iMsg As Object
Dim iConf As Object
Dim Flds As Variant
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
iConf.Load -1 ' CDO Source Defaults
Set Flds = iConf.Fields
With Flds
.Item("http://schemas.Microsoft.Com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.Microsoft.Com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.Microsoft.Com/cdo/configuration/sendusername") = "yourmail@gmail.Com"
.Item("http://schemas.Microsoft.Com/cdo/configuration/sendpassword") = "yourpassword"
.Item("http://schemas.Microsoft.Com/cdo/configuration/smtpserver") = "smtp.Gmail.Com"
.Item("http://schemas.Microsoft.Com/cdo/configuration/sendusing") = 2
.Item("http://schemas.Microsoft.Com/cdo/configuration/smtpserverport") = 25
.Update
End With
strbody = "Sample message " & Time
With iMsg
Set .Configuration = iConf
.To = sendto
.CC = ""
.BCC = ""
' Note: The reply address is not working if you use this Gmail example
' It will use your Gmail address automatic. But you can add this line
' to change the reply address .ReplyTo = "Reply@something.Com"
.From = "<mail to be displayed as @gmail.Com>"
.Subject = "subject"
.TextBody = strbody
.Send
End With
End Sub
-reply by shasunder
How To Send Email Using VB (using SMTP) ?
Hi All,
Is it possible to send mail with CC and BCC using MAPIMessages ?
Thanks in advance.
RK.
Dim iMsg As Object Dim iConf As Object Dim Flds As Variant Set iMsg = CreateObject("CDO.Message") Set iConf = CreateObject("CDO.Configuration") iConf.Load -1 ' CDO Source Defaults Set Flds = iConf.Fields With Flds .Item("http://schemas.Microsoft.Com/cdo/configuration/smtpusessl") = True .Item("http://schemas.Microsoft.Com/cdo/configuration/smtpauthenticate") = 1 .Item("http://schemas.Microsoft.Com/cdo/configuration/sendusername") = "yourmail@gmail.Com" .Item("http://schemas.Microsoft.Com/cdo/configuration/sendpassword") = "yourpassword" .Item("http://schemas.Microsoft.Com/cdo/configuration/smtpserver") = "smtp.Gmail.Com" .Item("http://schemas.Microsoft.Com/cdo/configuration/sendusing") = 2 .Item("http://schemas.Microsoft.Com/cdo/configuration/smtpserverport") = 25 .Update End With strbody = "Sample message " & Time With iMsg Set .Configuration = iConf .To = sendto .CC = "" .BCC = "" ' Note: The reply address is not working if you use this Gmail example ' It will use your Gmail address automatic. But you can add this line ' to change the reply address .ReplyTo = "Reply@something.Com" .From = "<mail to be displayed as @gmail.Com>" .Subject = "subject" .TextBody = strbody .Send End With
THEREis a error in the ".Send"
whatcan it be??
-reply by JOAO
Coba cara saya ini, tapi maaf saya kurang tau bahasa inggris jadi kamuterjemahkan aja ya ?
Private Sub AEMAIL()Set objEmail = CreateObject("CDO.Message")ObjEmail.From = "zanggi@yahoo.Com" 'bisa pakai sembarang email, tak masalah
ObjEmail.To = "romawu@yahoo.Co.Id"ObjEmail.CC = " "ObjEmail.BCC = " "ObjEmail.Subject = "indonesia" ObjEmail.TextBody = "Isi pesan yang akan disampaikan" 'untuk kirim file'objEmail.AddAttachment "C:ScriptsOutput.Txt" 'jika kamu mau mengirim file"
ObjEmail.Configuration.Fields.Item _("http://schemas.Microsoft.Com/cdo/configuration/Sendusing") = 2ObjEmail.Configuration.Fields.Item _("http://schemas.Microsoft.Com/cdo/configuration/smtpserver") = "125.160.6.252" 'ping dari server yang dapat dilihat dari commanfrom, dengan mengetikkan "ping smtp.Telkom.Net" ,jika kamu pakai speedy
objEmail.Configuration.Fields.Item _("http://schemas.Microsoft.Com/cdo/configuration/smtpserverport") = 25ObjEmail.Configuration.Fields.UpdateObjEmail.SendEnd Sub
-reply by k.Nizam, S.Kom
Hi,
Is there any way to send mail from gmail using SMSP.
I used the code which u have provided but not able to send the mail.
getting error message as
run time error
the transport failed to connect to the server.
please help me out
Thanks
using CDO objects I have got this message
The transport failed to connect to the server.
can any one help me against this problem
-reply by Farrukh jamal
I used a gmail address and got an error message as bellow:Error from Functions.SendEmail:The server rejected the sender address. The server response was: 530 5.7.0 Must issue a STARTTLS command first. F20sm1621609wfl.21Please help!!Thanks.
-question by kunthet
Similar Topics:
Php Send Email Problem
Php Send Mail Through Smtp
Php Send Mail Through Phpmailer
VB.NET: Howto Add And Delete Files Just looking for useful code (11)
|
(3) Manipulating Excel File With VB? opening and doing data stuff in vb
|
HOME 






