فرستادن ايميل با vb

Amin_vb

Member
بلاخره من يه كد كار كن برا فرستادن ايميل در vb پيدا كردم
اين كد از شي winsck استفاده مي كند و شما بايد يك شي از اين نوع با نام winsck1 روي فرم برنامه خود قرار دهيد سپس شما مي‌توانيد با استفاده از تابع SendEmail ايميل خود را ارسال نماييد
موفق باشيد
:lol: :lol: :lol:


کد:
Dim Response As String, Reply As Integer, DateNow As String
Dim first As String, Second As String, Third As String
Dim Fourth As String, Fifth As String, Sixth As String
Dim Seventh As String, Eighth As String
Dim Start As Single, Tmr As Single

Sub SendEmail(MailServerName As String, FromName As String, FromEmailAddress As String, ToName As String, ToEmailAddress As String, EmailSubject As String, EmailBodyOfMessage As String)
          
    Winsock1.LocalPort = 0 ' Must set local port to 0 (Zero) or you can only send 1 e-mail pre program start
    
If Winsock1.State = sckClosed Then ' Check to see if socet is closed
    DateNow = Format(Date, "Ddd") & ", " & Format(Date, "dd Mmm YYYY") & " " & Format(Time, "hh:mm:ss") & "" & " -0600"
    first = "mail from:" + Chr(32) + FromEmailAddress + vbCrLf ' Get who's sending E-Mail address
    Second = "rcpt to:" + Chr(32) + ToEmailAddress + vbCrLf ' Get who mail is going to
    Third = "Date:" + Chr(32) + DateNow + vbCrLf ' Date when being sent
    Fourth = "From:" + Chr(32) + FromName + vbCrLf ' Who's Sending
    Fifth = "To:" + Chr(32) + ToNametxt + vbCrLf ' Who it going to
    Sixth = "Subject:" + Chr(32) + EmailSubject + vbCrLf ' Subject of E-Mail
    Seventh = EmailBodyOfMessage + vbCrLf ' E-mail message body
    Ninth = "mouse mailer" + vbCrLf ' What program sent the e-mail, customize this
    Eighth = Fourth + Third + Ninth + Fifth + Sixth  ' Combine for proper SMTP sending

    Winsock1.Protocol = sckTCPProtocol ' Set protocol for sending
    Winsock1.RemoteHost = MailServerName ' Set the server address
    Winsock1.RemotePort = 25 ' Set the SMTP Port
    Winsock1.Connect ' Start connection
    
    WaitFor ("220")
    
    StatusTxt.Caption = "Connecting...."
    StatusTxt.Refresh
    
    Winsock1.SendData ("HELO worldcomputers.com" + vbCrLf)

    WaitFor ("250")

    StatusTxt.Caption = "Connected"
    StatusTxt.Refresh

    Winsock1.SendData (first)

    StatusTxt.Caption = "Sending Message"
    StatusTxt.Refresh

    WaitFor ("250")

    Winsock1.SendData (Second)

    WaitFor ("250")

    Winsock1.SendData ("data" + vbCrLf)
    
    WaitFor ("354")


    Winsock1.SendData (Eighth + vbCrLf)
    Winsock1.SendData (Seventh + vbCrLf)
    Winsock1.SendData ("." + vbCrLf)

    WaitFor ("250")

    Winsock1.SendData ("quit" + vbCrLf)
    
    StatusTxt.Caption = "Disconnecting"
    StatusTxt.Refresh

    WaitFor ("221")

    Winsock1.Close
Else
    MsgBox (Str(Winsock1.State))
End If
   
End Sub
Sub WaitFor(ResponseCode As String)
    Start = Timer ' Time event so won't get stuck in loop
    While Len(Response) = 0
        Tmr = Start - Timer
        DoEvents ' Let System keep checking for incoming response **IMPORTANT**
        If Tmr > 50 Then ' Time in seconds to wait
            MsgBox "SMTP service error, timed out while waiting for response", 64, MsgTitle
            Exit Sub
        End If
    Wend
    While Left(Response, 3) <> ResponseCode
        DoEvents
        If Tmr > 50 Then
            MsgBox "SMTP service error, impromper response code. Code should have been: " + ResponseCode + " Code recieved: " + Response, 64, MsgTitle
            Exit Sub
        End If
    Wend
Response = "" ' Sent response code to blank **IMPORTANT**
End Sub


Private Sub Command1_Click()
    SendEmail txtEmailServer.Text, txtFromName.Text, txtFromEmailAddress.Text, txtToEmailAddress.Text, txtToEmailAddress.Text, txtEmailSubject.Text, txtEmailBodyOfMessage.Text
    'MsgBox ("Mail Sent")
    StatusTxt.Caption = "Mail Sent"
    StatusTxt.Refresh
    Beep
    
    Close
End Sub

Private Sub Command2_Click()
    
    End
    
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)

    Winsock1.GetData Response ' Check for incoming response *IMPORTANT*

End Sub
 

miladmovie

Active Member
آقا من اين رو امتحان نكردم ولي لگر كار كنه كارت خيلي درسته :D
 

MAHDI_206

New Member
ارسال ایمیل از طریق ویژوال بیسیک

برای ارسال ایمیل از طربق VB6 بایستی از آبجکت اکتیو ایکس SMTP EASendMail استفاده نماید.

ابتدا باید به قسمت Reference بروید و اکتیو ایکس EASendMail را به پروژه خود اضافه کنید.

برای اینکار باید به منوی Project سپس به قسمت Import Type Library بروید و گزینه EASendMailObj ActiveX Object 1.0 Type Library را انتخاب نمایید و سپس OK را کلیک نمایید.
vb_easendmail.jpg

نکته : اگر این ActiveX در سیستم شما موجود نمی باشد. از قسمت پایین دانلود کنید و بعد به مسیر زیر انتقال دهید و مراحل بالا را تکرار کنید.

کد:
[B]C:\WINDOWS\system32[/B]

این هم کد کامل این برنامه :

[BASS]
Private Sub btnSendMail_Click()

Dim oSmtp As New EASendMailObjLib.Mail

oSmtp.LicenseCode = "TryIt"

' Set your Yahoo email address
oSmtp.FromAddr = Text1

' Add recipient email address
oSmtp.AddRecipientEx Text3, 0

' Set email subject
oSmtp.Subject = Text4

' Set email body
oSmtp.BodyText = Text5

' Yahoo SMTP server address
oSmtp.ServerAddr = "smtp.mail.yahoo.com"

' For example: your email is "[email protected]", then the user should be "[email protected]"
oSmtp.UserName = Text1
oSmtp.Password = Text2

' Because Yahoo deploys SMTP server on 465 port with direct SSL connection.
' So we should change the port to 465.
oSmtp.ServerPort = 465

' Detect SSL/TLS automatically
oSmtp.SSL_init

MsgBox "start to send email ..."

If oSmtp.SendMail() = 0 Then
MsgBox "email was sent successfully!"
Else
MsgBox "failed to send email with the following error:" & oSmtp.GetLastErrDescription()
End If

End Sub

[/BASS]
اینم کد ساده ارسال ایمیل :

[BASS]
Private Sub Command1_Click()

Dim oSmtp As New EASendMailObjLib.Mail
oSmtp.LicenseCode = "TryIt"

' Set your sender email address
oSmtp.FromAddr = "[email protected]"

' Add recipient email address
oSmtp.AddRecipientEx "[email protected]", 0

' Set email subject
oSmtp.Subject = "simple email from VB 6.0 project"

' Set email body
oSmtp.BodyText = "this is a test email sent from VB 6.0 project, do not reply"

' Your SMTP server address
oSmtp.ServerAddr = "smtp.emailarchitect.net"

' User and password for ESMTP authentication, if your server doesn't require
' User authentication, please remove the following codes.
oSmtp.UserName = "[email protected]"
oSmtp.Password = "testpassword"

' If your smtp server requires SSL connection, please add this line
' oSmtp.SSL_init

MsgBox "start to send email ..."

If oSmtp.SendMail() = 0 Then
MsgBox "email was sent successfully!"
Else
MsgBox "failed to send email with the following error:" & oSmtp.GetLastErrDescription()
End If

End Sub
[/BASS]




Pic_Send Email.jpg

تذکر : این کد فقط قادر است به پست های الکترونیکی درست شده با یاهو ارتباط برقرار نماید.
نکته : برنامه کاملی که تهیه شده کاملا تست شده است و هیچگونه عیبی ندارد. تنها کاری که شما بایستی انجام دهید به قسمت بروید و آبجکت را از لیست فعال بردارید و دوباره این آبجکت را به پروژه خود اضافه نمایید.

Send Email using Yahoo in VB 6.0

دانلود غیر مستقیم برنامه :

http://uplod.ir/5zhlx4xcltsi/Send_ma...ccount.zip.htm


دانلود غیر مستقیم Dll و عکس :

http://uplod.ir/xxdz7a36daaf/EASendMailObj.zip.htm
http://uplod.ir/w49ubovzp5au/vb_easendmail.jpg.htm
 

پیوست ها

  • EASendMailObj.zip
    209.6 کیلوبایت · بازدیدها: 74
  • Send mail using yahoo account.zip
    212.6 کیلوبایت · بازدیدها: 50
آخرین ویرایش:

kei

New Member
سلام.

من دانلود کردم ولی وقتی مشخصات رو میزنم و سند رو میزنم این ارور رو میده :

9-13-2014 9-44-23 PM.png
نمیدونم شاید activex رو نصب درست نکردم. میشه واصح بگید چیکارا باید بکنم تا بتونم ازش استفاده کنم؟؟؟
 

the_king

مدیرکل انجمن
سلام.

من دانلود کردم ولی وقتی مشخصات رو میزنم و سند رو میزنم این ارور رو میده :

مشاهده پیوست 106179
نمیدونم شاید activex رو نصب درست نکردم. میشه واصح بگید چیکارا باید بکنم تا بتونم ازش استفاده کنم؟؟؟
ActiveX ئه درست نصب شده اما Trial و آزمایشی بوده و کرک نشده بوده و دوره آزمایشی نصب اش روی سیستم تون تموم شده.
 

جدیدترین ارسال ها

بالا