I am trying to make a application through which I can send mail with attachement. I created and published onto server. If I am using it for sending mail without attachment it is working fine from my local machine. When I am attaching any
doc from my local through fileupload control , it is not picking that file and stating invalid path. It is expecting that file to the server, so that it can pick from there. But I have to take attachment from my local.
A.Venkatesan
Microsoft Certified Professional
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact venkatmca008@gmail.com
I used similer code. It is expecting attachment to be placed on server so that while sending mail it can pick file from server. My requirement is to use application hosted on server, just like any other web application, but attachment should be from my local.
I used similer code. It is expecting attachment to be placed on server so that while sending mail it can pick file from server. My requirement is to use application hosted on server, just like any other web application, but attachment should be from my local.
In that case, you can upload the file from local machine to the server first and then send the mail.You have to get it on server in order to send the mail.
ShyamMohan
Member
10 Points
10 Posts
Send mail with attachement
May 29, 2012 12:54 AM|LINK
I am trying to make a application through which I can send mail with attachement. I created and published onto server. If I am using it for sending mail without attachment it is working fine from my local machine. When I am attaching any doc from my local through fileupload control , it is not picking that file and stating invalid path. It is expecting that file to the server, so that it can pick from there. But I have to take attachment from my local.
Please help
venkatmca008
Participant
1810 Points
341 Posts
Re: Send mail with attachement
May 29, 2012 01:53 AM|LINK
plz u post ur code? sir.
Microsoft Certified Professional
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact venkatmca008@gmail.com
bhaskar.mule
Contributor
2270 Points
659 Posts
Re: Send mail with attachement
May 29, 2012 02:00 AM|LINK
hi
i hope it will help you
http://csharpektroncmssql.blogspot.com/2012/03/how-to-send-mail-with-attachment-in.html
Site:Rare technical solutions
ShyamMohan
Member
10 Points
10 Posts
Re: Send mail with attachement
May 29, 2012 02:50 AM|LINK
Hi Bhasker,
I used similer code. It is expecting attachment to be placed on server so that while sending mail it can pick file from server. My requirement is to use application hosted on server, just like any other web application, but attachment should be from my local.
majarajaking
Member
480 Points
432 Posts
Re: Send mail with attachement
May 29, 2012 04:29 AM|LINK
public void sendEmail()
{
MailMessage mM = new MailMessage();
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.From = new MailAddress("maddyrafi@gmail.com");
//msg.To.Add = MailAddress;
//MailAddress = TextBox5.Text;
msg.To.Add(TextBox5.Text);
//string ToAddress = TextBox5.Text.ToString();
msg.Subject = "Mail From Test Travel:";
msg.IsBodyHtml = true;
// msg.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName));
string mailBody = "sir,<br> <br> Thanks for Registration";
mailBody += "<br>Your password is: " + password + " <br> Username:" +TextBox2.Text+ " <br> <br> Thank you!! <br><br> Regards,<br><br> Test Travel";
msg.Body += mailBody.ToString();
msg.Priority = MailPriority.High;
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("maddyrafi@gmail.com", "rafi@1987");
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
object userstate = msg;
//msg.To.Add(ToAddress);
client.Send(msg);
}
msg.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName));
take 1 fileupload control and choose the file.
and finally call this sendEmail(); function after insert codings.
and Namespace is: using System.Net.Mail;
vijay_myl
Contributor
5070 Points
1068 Posts
Re: Send mail with attachement
May 29, 2012 05:00 AM|LINK
hi..
Refer the below link...to send mail with attachment like gmail..
http://www.dotnetcode.in/2011/06/how-to-send-mail-with-attachment-in.html
My .NET blog
Submit Article
nijhawan.sau...
All-Star
16430 Points
3173 Posts
Re: Send mail with attachement
May 29, 2012 05:02 AM|LINK
In that case, you can upload the file from local machine to the server first and then send the mail.You have to get it on server in order to send the mail.
ShyamMohan
Member
10 Points
10 Posts
Re: Send mail with attachement
May 29, 2012 05:25 AM|LINK
Hi Everyone.
Thanks...It got resolved. I'd to take fileupload.content too while doing attachment. Post that it is working fine.