hallo
how to send email with attachtment using c# ?
there are several example in internet about it ,but have' nt found one working
I have followed the instruction,including setting control panel----> administrative tools--->
IIs--->default SMTP Virtual Server --->properties--->Access--->Relay---> add 127.0.0.1 --->
--->delivery--->fill smart host with localhost ,change smart host with "mail.yahoo.com"
all doesnt work.
any help ?
thank you
han
Loading

Kirtan PatelRank #292 · 8.6K reputationPosted Dec 14, 2009, 7:53 PM EST
Yahoo Server Does not Provide..SMTP Service for Free
follow this great article ..you will have idea about sending mail with attachment .
http://www.c-sharpcorner.com/UploadFile/meetuchoudhary/sendmail08142009123125PM/sendmail.aspx
code is for asp.net but its working under Windows Form application too...
if my answer helped you then check "Do you like this answer" check box
Lalit MRank #1,186 · 1.5K reputationPosted Dec 14, 2009, 8:55 PM EST
MailMessage Mail = new MailMessage(); MailAddress ma = new MailAddress(txtFrom.Text,txtName.Text); Mail.From = ma; Mail.To.Add(txtTo.Text); if(txtCC.Text.Trim().Length != 0) Mail.CC.Add(txtCC.Text); if(txtBCC.Text.Trim().Length != 0) Mail.Bcc.Add(txtBCC.Text); Mail.Subject = txtSubject.Text; if (txtAttachment.Text.Trim().Length != 0) { string sAttach = txtAttachment.Text.Replace("\\","\\\\"); Mail.Attachments.Add(new Attachment(sAttach)); } //Note: When you make "IsBodyHtml" to true make //ValidateRequest="false" in page derective //As to make HTML content passed. Mail.IsBodyHtml = true; Mail.Body = txtComment.Text; //Setting Reply address. if (txtReplyTo.Text.Trim().Length != 0) { Mail.Headers.Add("Reply-To", txtReplyTo.Text); } else { Mail.Headers.Add("Reply-To", txtFrom.Text); } try { SmtpClient smtpMailObj = new SmtpClient(); //eg:localhost, 192.168.0.x, replace with your server name smtpMailObj.Host = "myMailServer"; smtpMailObj.Send(Mail); Response.Write("Your Message has been sent successfully"); } catch (Exception ex) { Response.Write("Message Delivery Fails"); }reference link
more info
hope you will get your answer,Thanks ....
hanafi tanudjaja41 reputationPosted Dec 14, 2009, 9:20 PM EST
thank you
it work
regard
han