dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Thread: Send email?

  1. #1
    Join Date
    Feb 2002
    Posts
    36

    Send email?

    Hi,

    I want to create a VB application to send e_mail automatically,
    but i don't know how to do that. I use lotus notes send and receive email via intranet in my company.I don't know how to set
    outlook to connect the company's mail service,so can't use outlook in the application. Anyone would like to give me some suggestion?

    Thanks in advance!

  2. #2
    Join Date
    May 2002
    Location
    Colombo,Sri Lanka
    Posts
    1,110
    Search the internaet there are many examples that u get how to send emails

    One of them

  3. #3
    Join Date
    Apr 2000
    Location
    Southampton, UK
    Posts
    329
    http://www.geocities.com/TimCottee goto downloads and get the .bas module for sending mail using Lotus Notes 4.x and 5.x
    TimCottee
    I know a little about a lot of things and a lot about very little.

    Brainbench MVP For Visual Basic
    http://www.brainbench.com

    MCP, MCSD, MCDBA, CPIM

  4. #4
    Join Date
    Aug 2002
    Location
    Maryland
    Posts
    9

    exaple i used

    'company Interactive Arts

    'usage inserted in code
    SendEmail txtEmailServer.Text, txtFromName.Text, txtFromEmailAddress.Text, txtToEmailAddress.Text, txtToEmailAddress.Text, txtEmailSubject.Text, txtMessage.Text


    Sub SendEmail(MailServerName As String, FromName As String, FromEmailAddress As String, ToName As String, ToEmailAddress As String, EmailSubject As String, EmailBodyOfMessage As String)
    Dim 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
    With Winsock1
    If .State = sckClosed Then ' Check to see if socket is closed
    DateNow = Format(Date, "Ddd") & ", " & Format(Date, "dd Mmm YYYY") & " " & Format(Time, "hh:mm:ss") & "" & " -0600"
    first = "mail from: " & FromEmailAddress & vbCrLf ' Get who's sending E-Mail address
    Second = "rcpt to: " & ToEmailAddress & vbCrLf ' Get who mail is going to
    Third = "Date: " & DateNow & vbCrLf ' Date when being sent
    Fourth = "From: """ & FromName & """ <" & FromEmailAddress & ">" + vbCrLf ' Who's Sending
    Fifth = "To: " & ToNametxt & vbCrLf ' Who it going to
    Sixth = "Subject: " & EmailSubject & vbCrLf ' Subject of E-Mail
    Seventh = EmailBodyOfMessage & vbCrLf ' E-mail message body
    Ninth = "X-Mailer: STMP Sender" & vbCrLf ' What program sent the e-mail, customize this
    .LocalPort = 0 ' Must set local port to 0 (Zero) or you can only send 1 e-mail per program start
    .Protocol = sckTCPProtocol ' Set protocol for sending
    .RemoteHost = MailServerName ' Set the server address
    .RemotePort = 25 ' Set the SMTP Port
    .Connect ' Start connection
    WaitFor ("220")
    StatusTxt.Caption = "Connecting...."
    .SendData ("HELO EnterComputerNameHere" & vbCrLf)
    WaitFor ("250")
    StatusTxt.Caption = "Connected"

    .SendData (first)
    StatusTxt.Caption = "Sending Message"

    WaitFor ("250")
    .SendData (Second)
    WaitFor ("250")
    .SendData ("data" & vbCrLf)
    WaitFor ("354")
    .SendData (Fourth & Third & Ninth & Fifth & Sixth & vbCrLf)
    .SendData (Seventh & vbCrLf)
    .SendData ("." & vbCrLf)
    WaitFor ("250")
    .SendData ("quit" & vbCrLf)
    StatusTxt.Caption = "Disconnecting"

    WaitFor ("221")
    .Close
    Else
    MsgBox (Str(.State))
    End If
    End With
    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 > 5 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 > 5 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
    David Whittington

    Thanks and may GOD bless!

  5. #5
    Join Date
    May 2002
    Location
    Montreal
    Posts
    450
    You can find a number of sample codes at http://www.freevbcode.com

    Go there and do a search on email. There are samples using Outlook and others using MAPI and SMTP servers and so on. That is a good place to start.

    Cheers,
    Laurent

  6. #6
    Join Date
    Feb 2002
    Posts
    36
    Thank you for all your replies!
    I will try them.
    Any else suggestion would be appreciated!

  7. #7
    Join Date
    Feb 2002
    Posts
    36
    Hi,

    The following codes works well! (from TimCottee)

    Thank you!
    /**********************************************/

    Public Sub SendNotesMail(Subject As String, Attachment As String, BodyText As String, SendTo As String, Optional CC As String = "", Optional BCC As String = "", Optional SaveIt As Boolean = False)
    'Set up the objects required for Automation into lotus notes
    Dim Maildb As Object 'The mail database
    Dim UserName As String 'The current users notes name
    Dim MailDbName As String 'THe current users notes mail database name
    Dim MailDoc As Object 'The mail document itself
    Dim AttachME As Object 'The attachment richtextfile object
    Dim Session As Object 'The notes session
    Dim EmbedObj As Object 'The embedded object (Attachment)
    'Start a session to notes
    Set Session = CreateObject("Notes.NotesSession")
    'Get the sessions username and then calculate the mail file name
    'You may or may not need this as for MailDBname with some systems you
    'can pass an empty string
    UserName = Session.UserName
    MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
    'Open the mail database in notes
    Set Maildb = Session.GETDATABASE("", MailDbName)
    If Maildb.ISOPEN = True Then
    'Already open for mail
    Else
    Maildb.OPENMAIL
    End If
    'Set up the new mail document
    Set MailDoc = Maildb.CREATEDOCUMENT
    With MailDoc
    .Form = "Memo"
    .SendTo = Split(SendTo, ",")
    .CopyTo = Split(CC, ",")
    .BlindCopyTo = Split(BCC, ",")
    .Subject = Subject
    .Body = BodyText
    .SAVEMESSAGEONSEND = SaveIt
    'Set up the embedded object and attachment and attach it
    Dim aryAttachment() As String
    aryAttachment = Split(Attachment, "|")
    For intAttach = LBound(aryAttachment) To UBound(aryAttachment)
    Set AttachME = .CREATERICHTEXTITEM("Attachment" & CStr(intAttach))
    Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", aryAttachment(intAttach), "Attachment" & CStr(intAttach))
    .CREATERICHTEXTITEM ("Attachment" & CStr(intAttach))
    Next intAttach
    'Send the document
    .PostedDate = Now() 'Gets the mail to appear in the sent items folder
    .SEND False
    End With
    'Clean Up
    Set Maildb = Nothing
    Set MailDoc = Nothing
    Set AttachME = Nothing
    Set Session = Nothing
    Set EmbedObj = Nothing
    End Sub

  8. #8
    Join Date
    Feb 2002
    Posts
    36
    Hi,

    sorry,another problem:

    When i send a email in my application with outlook, a dialog pop
    up with the warning message of " A program is trying to automatically send e-mail...,do you want to allow this".
    How can i hide it?

    Thanks in advance!

  9. #9
    Join Date
    Apr 2000
    Location
    Southampton, UK
    Posts
    329
    tangbing, this is a known issue. The reason is that you are either running Outlook 2002 or previous versions with the outlook security patch applied. This is designed to prevent virus software from plundering the outlook address book and automatically sending mails to all and sundry without your knowledge. It does however have the side effect of causing problems with legitimate mails that you want to send in the background without user intervention. I am not aware of a "nice" workaround for this, there is apparently a product somewhere which can do it but I have not been able to locate it yet. I use the vbSendMail dll http://www.freevbcode.com/ShowCode.Asp?ID=109 which allows you to send smtp mail to using any known and reachable smtp server.
    TimCottee
    I know a little about a lot of things and a lot about very little.

    Brainbench MVP For Visual Basic
    http://www.brainbench.com

    MCP, MCSD, MCDBA, CPIM

  10. #10
    Join Date
    Oct 2001
    Location
    Carmi,IL. USA
    Posts
    30
    Hello:

    Here is a link to a mail sending program that I use. It works very well for me, maybe it will work for you also. (It is FREE)

    www.aspemail.com

    David M. Camp

  11. #11
    Join Date
    Feb 2002
    Posts
    36
    Hi,

    I tried desprate4help's suggestion and found it is the best
    method to send a email in a vb application. Maybe the vbSendMail.dll that TimCottee metioned has been written in the
    same way.

    Thanks!

  12. #12
    Join Date
    Feb 2002
    Posts
    36
    Hi,
    desprate4help,I still have a problem!
    If the mail server require authentication,how can i send my
    mail address ,user name and password to it?

    any response would be appreciatate!

    Thanks in advance!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)