Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Sending Email

Hello All,

I Have a problem in Sending Email through Macro.

earlier it was working fine but recently it is showing error.

When I run the macro it stoping at

objEmail.Send

Error Message :

The message could not be sent to the SMTP server. The transport error code was 0x80040217. The server response was not available

Please help me on this issue.

Thanks,

1 Solution

Accepted Solutions
marcus_malinow
Partner - Specialist III
Partner - Specialist III

Hi Surender,

have you seen this - smtp - Getting Error Transport error code was 0x80040217 while Sending Email in Asp.Net - Stack Over...

One possible cause might be that your email account has been locked.

Marcus

View solution in original post

9 Replies
bindu_apte
Creator III
Creator III

Hi,

Can you please share the macro code which you are executing

Not applicable
Author

Hi Bindu,

Please check below code

sub Export

'dim excelFile

'Set the path where the excel will be saved

path= "C:\Users\Desktop\Report"

    filePath = path &".xls"

    'Create the Excel spreadsheet

    set oXL=CreateObject("Excel.Application")

oXL.visible=False

Set curWorkBook= oXL.Workbooks.Add

aSheetObj=Array("CH52")

usedRows=0

oXL.Sheets.Add 

Set oSH = oXL.ActiveSheet

oSH.Range("A1").Select  

Set obj = ActiveDocument.GetSheetObject(aSheetObj(0))

obj.CopyTableToClipboard True

oSH.Paste

sCaption=obj.GetCaption.Name.v

set obj=Nothing

  

oSH.Rows("1:1").Select

oXL.Selection.Font.Bold = True     

oSH.Cells(1,1).Select

oXL.Selection.Columns.AutoFit

oSH.Range("A1").Select   

oSH.Name=left(sCaption,30) 

set oSH=Nothing

oXL.Visible = False

oXL.DisplayAlerts = False

'Save the file and quit excel

    curWorkBook.SaveAs filePath

    curWorkBook.Close

    oXL.Quit

'set oXL=Nothing

Dim objEmail

  Const cdoSendUsingPort = 2 ' Send the message using SMTP

  Const cdoBasicAuth = 1     ' Clear-text authentication

  Const cdoTimeout = 60       ' Timeout for SMTP in seconds

     mailServer = "Server IP"

     SMTPport =25

     mailusername = "Mail ID"

     'mailpassword = ""

     mailto = "To Mail ID list"

  

   

     mailSubject = "Test mail to test macro"

     body = "<html><body> Dear All, <br> <br>Pl find attached<br> </body></html>"

  Set objEmail = CreateObject("CDO.Message")

  Set objConf = objEmail.Configuration

  Set objFlds = objConf.Fields

  With objFlds

    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort

    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = mailServer

  .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = SMTPport

  .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasicAuth

      '.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = cdoTimeout

  .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = mailusername

  .Item("http://schemas.microsoft.com/cdo/configuration/smtpaccountname") = mailusername

  '.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = mailpassword

  '.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1

    .Update

  End With

  objEmail.To = mailto

  objEmail.From = mailusername

  'objEmail.CC =

  objEmail.Subject = " Report."

  objEmail.HTMLBody = body

  objEmail.AddAttachment filePath

  objEmail.Send

  Set objFlds = Nothing

  Set objConf = Nothing

  Set objEmail = Nothing

    Set curWorkBook = nothing

    Set oXL= nothing

ActiveDocument.Save

ActiveDocument.GetApplication.Quit

End Sub

marcus_malinow
Partner - Specialist III
Partner - Specialist III

Surender,

a couple of things to check:

Check whether the SMTP server and service are actually running. Has the service been moved?

Check if permissions have been changed on it. Was it previously set to allow anonymous access? Does the QlikView service account have permissions on it? (Assuming that you are running this from your QlikView server)

Marcus

Not applicable
Author

Thanks Marcus,

I Have checked SMTP Server and Services it working fine. Access also we are given anonymous access.

Yes Qlikview service have permission.

Through Qlikview Publisher mails are generating fine but through macro there is a problem.

Regards

Surender

syukyo_zhu
Creator III
Creator III

Hi,

Did you check your recepient is always avaiable et not be deleted?

hope helpful

sampada0810
Creator
Creator

This can be even achieved by using NPrinting

Not applicable
Author

yes Have checked with one mail ID also.

Not applicable
Author

My Company is not ready to buy Nprinting now.

through Macro also we can send the Excel files.

marcus_malinow
Partner - Specialist III
Partner - Specialist III

Hi Surender,

have you seen this - smtp - Getting Error Transport error code was 0x80040217 while Sending Email in Asp.Net - Stack Over...

One possible cause might be that your email account has been locked.

Marcus