+ Reply to Thread
Results 1 to 10 of 10

mail trought smtp with attached file

Hybrid View

  1. #1
    Registered User
    Join Date
    02-03-2011
    Location
    Bulgaria, Europe
    MS-Off Ver
    2007, 2013
    Posts
    59

    Red face mail trought smtp with attached file

    Hi all,
    I try to find solution to send mail with macros via SMTP

    Private Sub CommandButton1_Click()
    Dim Mail As New Message
    
    Dim Config As Configuration: Set Config = Mail.Configuration
    
    Config(cdoSendUsingMethod) = cdoSendUsingPort
    Config(cdoSMTPServer) = “smtp.gmail.com”
    Config(cdoSMTPServerPort) = 25
    Config(cdoSMTPAuthenticate) = cdoBasic
    Config(cdoSMTPUseSSL) = True
    Config(cdoSendUserName) = “youremail@gmail.com”
    Config(cdoSendPassword) = “yourgmailpassword”
    Config.Fields.Update
    
    Mail.To = “your_recipient@whereever.com”
    Mail.From = Config(cdoSendUserName)
    Mail.Subject = “Subject from VBA”
    Mail.HTMLBody = “Body from VBA”
    
    Mail.Send
    MsgBox “Sent”
    
    End Sub
    how to add attachment?
    thank you in advance!
    Last edited by rodich; 06-22-2015 at 04:23 AM.
    ?If you have an apple and I have an apple and we exchange these apples then you and I will still each have one apple. But if you have an idea and I have an idea and we exchange these ideas, then each of us will have two ideas.?

    George Bernard Shaw

  2. #2
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: mail trought smtp with attached file

    try this

    Mail.Addattachment <filename with path>
    this assumes the file is saved somewhere....
    Ernest

    Please consider adding a * if I helped

    Nothing drives me crazy - I'm always close enough to walk....

  3. #3
    Registered User
    Join Date
    02-03-2011
    Location
    Bulgaria, Europe
    MS-Off Ver
    2007, 2013
    Posts
    59

    Re: mail trought smtp with attached file

    many thanks!!!!

  4. #4
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: mail trought smtp with attached file

    Glad I could help

    If this has been completed to your satisfaction, please set the thread to Solved...If you feel I deserve an increase in my reputation, feel free to click on the star in the lower left of the thread. Remember, someday when you help somebody they may add to your rep points, and it could be me...just a thought...

  5. #5
    Registered User
    Join Date
    02-03-2011
    Location
    Bulgaria, Europe
    MS-Off Ver
    2007, 2013
    Posts
    59

    Re: mail trought smtp with attached file

    I'm sorry that I disturb you again
    but I have "User-defined type not defined" error when trying to send e-mail immediately in first row

    Dim Mail As New Message
    Dim Config As Configuration: Set Config = Mail.Configuration
    
    Config(cdoSendUsingMethod) = 2 ' cdoSendUsingPort
    Config(cdoSMTPServer) = "bla-bla"                
    Config(cdoSMTPServerPort) = 25
    Config(cdoSMTPConnectionTimeout) = 30
    Config(cdoSMTPAuthenticate) = cdoAnonymous
    ........
    finally I have to send mail without creation new mail throught Outlook

  6. #6
    Registered User
    Join Date
    02-03-2011
    Location
    Bulgaria, Europe
    MS-Off Ver
    2007, 2013
    Posts
    59

    Re: mail trought smtp with attached file

    in additional I use Excel 2013

  7. #7
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: mail trought smtp with attached file

    this is how I do it...

    Sub SendEmail()
    
        Dim EmailTo As String, FileDir As String
        Dim objmessage As Object
        Dim i As Integer
    
        EmailTo = "billyjoejimbob@abc.com"
    
        Set objmessage = CreateObject("CDO.Message")
        objmessage.Subject = "Place Subject data here"
        objmessage.From = "me@bfd.com"
        objmessage.To = "everybody@intheworld.com"
        
        objmessage.addattachment "Path\filename"
    
    
        objmessage.TextBody = Body
        objmessage.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        objmessage.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp server name here"
        objmessage.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
        objmessage.Configuration.Fields.Update
        objmessage.Send
        
    End Sub
    yes, this is for 2010....this will also directly send through the SMTP server...
    Last edited by judgeh59; 06-19-2015 at 11:15 AM.

  8. #8
    Registered User
    Join Date
    02-03-2011
    Location
    Bulgaria, Europe
    MS-Off Ver
    2007, 2013
    Posts
    59

    Re: mail trought smtp with attached file

    Thank you, judgeh59!!
    It's very useful for me!

    the last question
      EmailTo = "billyjoejimbob@abc.com"
    
        Set objmessage = CreateObject("CDO.Message")
        objmessage.Subject = "Place Subject data here"
        objmessage.From = "me@bfd.com"
        objmessage.To = "everybody@intheworld.com"

    whats mean "EmailTo"?

  9. #9
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: mail trought smtp with attached file

    that's who you are emailing to....

  10. #10
    Registered User
    Join Date
    02-03-2011
    Location
    Bulgaria, Europe
    MS-Off Ver
    2007, 2013
    Posts
    59

    Re: mail trought smtp with attached file

    Yes, of course
    I asked you because are twice EmailTo and objmessage.To
    Thank you again !!
    All is perfect!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. SMTP E-mail server not connects Outlook
    By joe41 in forum Outlook Formatting & Functions
    Replies: 2
    Last Post: 04-14-2009, 05:42 AM
  2. Recording date Excel file is attached to e-mail?
    By Mike in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-18-2006, 02:15 PM
  3. [SOLVED] URGENT! Please please help me get smtp mail send working..
    By Duncan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-27-2006, 09:55 AM
  4. [SOLVED] Sending mail from Excel with CDO - return SMTP value
    By Kent in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-22-2005, 12:06 PM
  5. Sending mail with Excel file attached, and cell-value inserted in Subject line
    By arunjoshi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-07-2005, 09:41 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1