Mail con allegato

venerdì 29 settembre 2006 - 19.29

Gemini Profilo | Expert

Ciao a tutti
come faccio a inviare una mail con allegata un file presente sul server?
Grazie mille

Brainkiller Profilo | Guru

>Ciao a tutti
>come faccio a inviare una mail con allegata un file presente
>sul server?

Beh, ti riporto un esempio tratto dall'SDK:

//This example shows how to programmatically add attached files //to a mail lessage. MailMessage myMail = new MailMessage(); // Concatenate a list of attachment files in a string. string sAttach = @"C:\images\image1.jpg,C:\images\image2.jpg,C:\images\image3.jpg"; // Build an IList of mail attachments using the files named in the string. char[] delim = new char[] {','}; foreach (string sSubstr in sAttach.Split(delim)) { MailAttachment myAttachment = new MailAttachment(sSubstr); myMail.Attachments.Add(myAttachment); }

In questo esempio vengono inseriti ben 3 allegati.
A te ne basta uno. Se l'allegato è sul Server è sufficiente che rilevi il percorso fisico esatto cioè c:\web\ecc. e di solito si fa uso del metodo Server.MapPath("/") che ti restituisca il percorso fisico della root del sito.
Ciao

David De Giacomi | Microsoft MVP
http://blogs.dotnethell.it/david/
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5