Solved

c# winform send mail

Posted on 2008-10-31
7
2,457 Views
Last Modified: 2013-12-17
Hi,
I am working on windowsform application. Finally this application would be installed on clients machine.
I have to integrate mail module in my application.

How can it be done. What namespaces should i import in C# . Any example.

Should the client machine have smtp server installed
0
Comment
Question by:dotnet0824
7 Comments
 
LVL 13

Accepted Solution

by:
SameerJagdale earned 150 total points
ID: 22848269
In order to send email in C# code, do the following:
 

// create mail message object
MailMessage mail = new MailMessage();
mail.From = "";           // put the from address here
mail.To = "";             // put to address here
mail.Subject = "";        // put subject here	
mail.Body = "";           // put body of email here
SmtpMail.SmtpServer = ""; // put smtp server you will use here 
// and then send the mail
SmtpMail.Send(mail);

Open in new window

0
 
LVL 8

Assisted Solution

by:rpkhare
rpkhare earned 100 total points
ID: 22848273
0
 
LVL 13

Expert Comment

by:SameerJagdale
ID: 22848277
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:dotnet0824
ID: 22848305
Is there any Inbuilt methods in .NET I can use???? What imports statement should i use

MailMessage mail = new MailMessage();  (Is this 3rd party) I cant find it in .NET
0
 
LVL 5

Assisted Solution

by:rendaduiyan
rendaduiyan earned 75 total points
ID: 22848376
using System.Net.Mail;

       
MailAddress from = new MailAddress("xxxi@xxx.com", "xxxx");
        MailAddress to = new MailAddress("xxx@xxx.com", "xxx");
        MailMessage mail = new MailMessage(from, to);  
        foreach(ListItem li in this.DropDownList2.Items)
        {
            MailAddress one = new MailAddress (li.Text);
            if(one.User != "xxx")
            {
                mail.To.Add(one);
            }
        }
        
        mail.Subject = "books status updated";
        mail.Priority = MailPriority.Normal;
        mail.IsBodyHtml = false;
        mail.Body = "this mail is sent by " + Server.MachineName
            + " automatically. Please go to http:/xxx for details." 
            + Environment.NewLine
            + this.TextArea1.Value;
        SmtpClient client = new SmtpClient("sgp-sg-mb01.sgp.agilent.com");
        client.Credentials = CredentialCache.DefaultNetworkCredentials;
        client.Send(mail);

Open in new window

0
 
LVL 13

Expert Comment

by:SameerJagdale
ID: 22849426
it's in .net
make sure you import the namespace,
Imports System.Net.Mail
 
0
 
LVL 9

Assisted Solution

by:gdupadhyay
gdupadhyay earned 75 total points
ID: 22850633
I already give a answer of this question, but for different expert.

You can find out accepted solution on:

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_CSharp/Q_23688815.html
Please let me know, if you have any question.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

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