本文介绍了发送邮件时限制附件文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





下面的代码块对我有用。



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()







如何查看Attchment filesize?



如果Attchment超过2MB,那么Attchment将自动发送到FTP文件夹中,消息正文将是;



亲爱的客户,



文件附件很大。请访问FTP文件夹,然后获取Attchment。





谢谢。

请帮助我。




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.

推荐答案

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.


这篇关于发送邮件时限制附件文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 00:26