Click here to Skip to main content
12,244,103 members (56,422 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB VB.NET
Hi,

Code block below is working for me.

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 16-Jan-13 0:08am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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

Thus :

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.
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160426.1 | Last Updated 16 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100