[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

attachemnt file at gmail not working

Posted on 2011-04-24
3
Medium Priority
?
185 Views
Last Modified: 2012-05-11
look at code plaeae what is the error
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net.Mail;
using System.Net;

public partial class send2 : System.Web.UI.Page
{

    protected void Button1_Click(object sender, EventArgs e)
    {
        string file = Server.MapPath("xml/Xml_student2011.xml");
        sendmail1("nabooln@gmail.com", "nabooln@gmail.com", "subject", "body", file);
    }
    public static bool sendmail1(string sender, string recipient, string subject, string body, string file)
    {
        //Create Mail Message Object with content that you want to send with mail.
        MailMessage myMailMessage = new MailMessage();

        myMailMessage.To.Add(recipient);
        myMailMessage.From = new MailAddress(sender);
        myMailMessage.Subject = subject;
        myMailMessage.Body = body;
        Attachment myAttachment = new Attachment(file);
        myMailMessage.Attachments.Add(myAttachment);
       
        NetworkCredential mailAuthentication = new NetworkCredential("mydrhow@gmail.com", "xxxxx");
        SmtpClient mailClient = new SmtpClient("smtp.gmail.com");


        //Enable SSL
        mailClient.EnableSsl = true;
        mailClient.Port = 587;
        mailClient.Credentials = mailAuthentication;
        try
        {
            mailClient.Send(MyMailMessage);
            return true;
        }
        catch (Exception ex)
        {
            string ex2 = ex.ToString();
            return false;
        }
    }
}

Open in new window

0
Comment
Question by:myaspnet
  • 2
3 Comments
 
LVL 1

Author Comment

by:myaspnet
ID: 35456159
this is error
 mailClient.Send(MyMailMessage);
0
 
LVL 4

Accepted Solution

by:
malikirfan28 earned 1500 total points
ID: 35456186
There is a syntax error at "mail
try
        {
            mailClient.Send(MyMailMessage);            return true;
        }

If it is just typo mistake here then have a look here
0
 
LVL 1

Author Closing Comment

by:myaspnet
ID: 35729454
very good
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month18 days, 5 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question