Click here to Skip to main content
15,909,591 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Code block below is working for me.

VB
Imports System.Net.Mail




Dim SmtpServer As New SmtpClient()

        Dim mail As New MailMessage()

        SmtpServer.Credentials = New _
                                 Net.NetworkCredential(AppSettings.Get("smtpID"), _Globalvariables.DecryptSmtp_pWd)


        SmtpServer.Port = 25

        SmtpServer.EnableSsl = False

        SmtpServer.Host = AppSettings.Get("smtpHost")

        mail = New MailMessage()

        mail.From = New MailAddress(AppSettings.Get("mailFrom"), AppSettings.Get("displayname"))

        mail.To.Add(email_id)

        mail.CC.Add(AppSettings.Get("mailCC"))

        mail.Subject = AppSettings.Get("mailSubject") & "(" & sMonthName & iYear & ")"

        mail.Body = "<b>Hi,</b><br></br> " & vbCrLf

        mail.Body = mail.Body + "Monthly Generation of AuditSys Users Invalid Log-in" & vbCrLf

        mail.Body = mail.Body + "for the Month of " & sMonthFullName & " " & iYear & ". <br></br> " & vbCrLf


        mail.IsBodyHtml = True


        Dim Attchment As Attachment = New Attachment(AppSettings.Get("CMSDIR") & AppSettings.Get("Local_DIR") & AppSettings.Get("RptFileName") & AppSettings.Get("xls_extension"))

        mail.Attachments.Add(Attchment)

        SmtpServer.UseDefaultCredentials = False

        SmtpServer.Send(mail)

        mail.Dispose()



How can i check the Attchment filesize ?

so that if Attchment is more than 2MB then Attchment will automatically be sent in the the FTP folder, and the body of the message will be;

Dear Client,

File attachment was large. Please access FTP Folder instead and get Attchment.


Thank You.
Please Help Me.
Posted

1 solution

From what you told, there must be somewhere on your server a file that you use as attachment.

Thus :

VB
using System.IO;

Dim filePath As String = AppSettings.Get("CMSDIR") & AppSettings.Get("Local_DIR") & AppSettings.Get("RptFileName") & AppSettings.Get("xls_extension")
Dim fi As FileInfo = new FileInfo(filePath);

If (fi.Length > 2097152)
   [your logic here when you want to send it to ftp]
Else
   [your logic here when you want as attachment]
End If


Hope this helps.
Kind regards.
 
Share this answer
 
v2
Comments
Alan Tuscano 16-Jan-13 22:43pm    
Thanks phil.o, its working!
phil.o 17-Jan-13 3:44am    
You're welcome ! Glad to help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900