Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hai All,

while sending mail,i got one error like this Unable to cast object of type 'System.Net.Mail.AttachmentCollection' to type 'System.Web.Mail.MailAttachment'.
anyone can solve dis one...? pls help me


Thnks Advnc
Aatif Ali Bangalore
Posted
Comments
Prasad_Kulkarni 14-Jun-13 8:53am    
Can you post your code Atif?
Aatif Ali from Bangalore 14-Jun-13 9:00am    
public void SendMsgAttachmnts(System.Net.Mail.MailMessage message)
{
try
{
/* new changes for mail.winreo.net server */
System.Web.Mail.SmtpMail.SmtpServer = UNI.Core.ConfigurationManager.GetApplicationSetting("EmailManager.MailServer");
string from = Core.ConfigurationManager.GetApplicationSetting("EmailManager.SenderAddress");
System.Web.Mail.MailMessage webmessage = new System.Web.Mail.MailMessage();
webmessage.From = string.Format("REOU<{0}>", from);
webmessage.To = message.To.ToString();
webmessage.Subject = message.Subject.ToString();
webmessage.Body = message.Body;
webmessage.BodyFormat = System.Web.Mail.MailFormat.Html;

//System.Web.Mail.MailAttachment attachment;
//attachment = new System.Web.Mail.MailAttachment("c:\\intrspace.pdf");
webmessage.Attachments.Add(message.Attachments);

//webmessage.Attachments.Add(
System.Web.Mail.SmtpMail.Send(webmessage);
}
CHill60 14-Jun-13 8:59am    
You will need to specify which one of the attachments you are using ... e.g. [0] at the end
Aatif Ali from Bangalore 14-Jun-13 9:01am    
i got error only in attachmnt line...

1 solution

Try:
C#
webmessage.Attachments.AddRange(message.Attachments);
 
Share this answer
 
Comments
Aatif Ali from Bangalore 15-Jun-13 0:07am    
.Addrange is not getting...only add option is here....

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