.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

SMTP email from CLR

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :

Have this code.

    public static string SendEmail(string psSubject,

         string psBodyText,string psToName, string psToEmail,

         string psFromName,string psFromEmail,string psHost,

         int piPort,int piTimeout, string psSmtpUser, string psSmtpPassword,

         bool pbSmtpSSL)


            //new message

       MailMessage loMsg = new MailMessage();

            //SMTP settings

       SmtpClient loSMTPServer = new SmtpClient(psHost,piPort); ---- it blows up right here with a security thing.

I have tried adding a signed certificate to my assembly and got a .pfx file with a password on it, and it is still blowing up.  Apparently, I am still missing a step.  

Any ideas what that step is?

Assembly is marked 'unsafe'.


View Complete Post

More Related Resource Links

smtp is noe sending email instantly,it makes a Queue in my local system

I am using a  smtp to send email from asp.net (C#)code.it sending some email instantly but many of email is making a queue in my Inetpub folder at local system.what could be the issue ? please help me to get rid from it.ThankxArvind

Trying to email through SMTP on server 2008

I have the following form and trying to click a button and email through an SMTP server. Any suggestions? Thanks.<table class="style1" bgcolor="#003366" cellpadding="3" cellspacing="3"> <tr> <td class="style2"> Your name:<br /> <asp:TextBox ID="txtHDName" runat="server" Width="161px"></asp:TextBox> <br /></td> </tr> <tr> <td class="style2"> Your email:<br /> <asp:TextBox ID="txtEmail" runat="server" Width="161px"></asp:TextBox></td> </tr> <tr> <td class="style2"> PC name:<br /> <asp:DropDownList ID="DropDownList1" runat="server"> </asp:DropDownList> </td> </tr> <tr> <td class="style2"> Problem:<br /> <asp:DropDownList ID="DropDownList2" runat="server" Width="128px"> </asp:DropDownList> &l

What will be the correct smtp settings for sending out email from an asp.net website to gmail's bus

Hi,I have setup a gmail's business account for my company.Now I want to receive all the emails like ContactUs, Qoute Email, etc from my website to that account i.e. info@mydomainname.com I have added the following smtp settings behind my web formsSmtpClient smtpClient = new SmtpClient("localhost",25); //Providing Network credentials smtpClient.Credentials = new System.Net.NetworkCredential("quote@mydomainname.com", "password"); smtpClient.UseDefaultCredentials = true; smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; MailMessage mail = new MailMessage(); //HTML Mail Format mail.IsBodyHtml = false; //Setting Form , To and CC mail.From = new MailAddress("quote@mydomainname.com", "My Web Site"); mail.To.Add(new MailAddress("info@mydomainname.com")); This code gives me feedback "email has successful sent"  but it does not send any email to info@mydomainname.comCan anyone let me know what will be the correct smtp settings for sending out emails to gmail's business accounts?Regards,Dazy

Configure Incoming Email in SharePoint 2010 with a remote (public) SMTP Server

I have a standalone SharePoint 2010 Installation on my local network. Have configured the SMTP Services and a SMTP domain called "internalcompany.com". Created a hosts file entry also for that - now outlook is able to send emails to this domain; it reaches the drop folder and from there SharePoint picks it up and pushes to the document libraries. So far so good. But obviously this is not what I want to do: my www.company.com is my public domain and mail server is mail.company.com - how do I get the local SMTP point to this address - so that if someone sends an email to shareddocs@company.com (just like any other normal id), it comes to my local server and then SharePoint. How do I do this? Remember, my server is standalone and my network is not domain based and does not have exchange.Karthick

Sending email via SmtpClient() not working with smtp.gmail.com :(

Help I cannot seem to send an email via my gmail account using "C#" why not?   <system.net> <mailSettings> <smtp deliveryMethod="Network" from="ian.coetzer@gmail.com"> <network host="smtp.gmail.com" port="587" enableSsl ="true" defaultCredentials ="false" password ="xxxxxx" userName ="ian.coetzer@gmail.com"></network> </smtp> </mailSettings> </system.net> SmtpClient smtpClient = new SmtpClient(); MailMessage message = new MailMessage(); try { message.To.Add(emailTo); message.Subject = ""; message.Body = GetEmailBody(userName, password, url); smtpClient.Send(message); return true; } catch(Exception ex) { throw new ApplicationException("Could not send notification.", ex); }   I.W Coetzer

sending email using IIS smtp service


 I am working on an email that someone will send from one of our main sites requesting an account password.  I am using System.Net.Mail.MailMessage to create the email and then sending it using System.Net.Mail.SmtpClient.  Below is my code: 

	Public Function sendEmail(ByVal address As String) As String
		Dim mailMessage As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage()
		mailMessage.To.Add(New System.Net.Mail.MailAddress("emailAddress"))
		mailMessage.From = (New System.Net.Mail.MailAddress(address))
		Dim smtpClient As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient()
		Catch ex As Exception
			Throw New ApplicationException("Data Error", ex)
		End Try
	End Function

	Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
	End Sub

Then in my web.config file I have the following

				<network host="cook.CMAP.public" port="25" 
It all looks like it is right bu

smtp sending email twice.


I am using .net membership functionality, The problem is on forget password page it send two emails to the user , any idea why?

I am using Windows 2008 Server.

Imports System.Net.Mail

Partial Class registration_ForgotPassword
    Inherits System.Web.UI.Page
    Protected Sub btnSendPassword_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSendPassword.Click
    End Sub

#Region "SendForgotPasswordEmail"
    Private Sub SendForgotPasswordEmail()
        Dim emailFrom As String = ConfigurationManager.AppSettings("EmailFrom").ToString()

        Dim message As String = String.Empty
        Dim emailTo As String = txtEmail.Text

        Dim username As String
        Dim password As String
        password = ""

        Dim list As MembershipUserCollection
        list = Membership.FindUsersByEmail(emailTo)

        If list.Count > 0 Then
            username = Membership.GetUserNameByEmail(emailTo)
            password = list(username).ResetPassword()

            Dim msg As String = ""
            msg = "Your password is " + password

            msg = msg & "</br> As this is a temporary password please immediately change your password after login."
            message = msg
            Dim objmm As New MailMessag

Unable to send email with smtp client


I'm not able to get email working on my site. I have followed the instructions for this host. This should be very straightforward. Here is my current web.config.  

			<smtp deliveryMethod="Network" from=".com">
				<network host="localhost" port="25" userName=".com" password="" />
 Public Shared Function SendSimpleMail(ByVal fromAccount As String, ByVal toAccount As String, ByVal title As String, ByVal msg As String) As Boolean
            HttpContext.Current.Response.Write("FROM: " & fromAccount & " TO: " & toAccount & "TITLE: " & title & msg)
            Dim eMail As New System.Net.Mail.MailMessage()
            eMail.IsBodyHtml = True
            eMail.Body = msg
            eMail.From = New System.Net.Mail.MailAddress(fromAccount)
            eMail.Subject = title
            Dim SMTP As New System.Net.Mail.SmtpClient
            'SMTP.UseDefaultCredentials = False
            'SMTP.Credentials = New System.Net.NetworkCredential(".com&quo

SMTP Email delete file C#



I have a ASP.Net website in which an email has to be sent to user with an excel attached if the user requests.

The user provides the email address, when click on a button to send report, an excel report with the result set should be attached to the email and sent to user.

The excel report will be saved on the server and through SMTP, I'm senidng the report in email. After the email is sent I should delete the excel file created on the server.When I'm trying to delete I get the error, the file is being used by SMTP object (other process).

Is there a way that I can delete this file after the email is sent? Please help me.



Using WCF Service to Email with smtp.gmail


I am using silverlight 4 and I have implemented a WCF service to email my gmail account through the app.

My smtp.Send(msg) line is failing and sending it into the catch statement.

I'm not sure where the problem is but posted below is my code for the WCF service method it is failing in.

public bool SendMail(string emailTo, string emailFrom, string msgSubject, string msgBody)
            bool success = false;
                MailMessage msg = new MailMessage();

PrintPocketCE Print Pocket Excel, Pocket Word and email files

Version 3.560 (May 15, 2009):

Important bug fix: a slight difference in how some devices create fonts was causing a few devices to have significantly longer print times for large print jobs.

Adjusted PocketJet printer paper feed commands

Other minor fixes and enhancements.

Version 3.559 (Mar 5, 2009):

Added support for Martel MCP78xx printers

Version 3.558 (Aug 20, 2008):

Added support for Martel MCP78xx printers

Version 3.557 (June 27, 2008):

Fixed error in Canon printer support

Fixed COM0 port selection

Version 3.556 (June 15, 2008):

Added support for Brother MW-260

Added support for Sato MB400

Version 3.555 (Aug 8, 2007):

Added support for Pentax RuggedJet 3 and RuggedJet 4 printers

Changed Epson TM-P60 support to maximum page width of 1200 dots

Version 3.551 (Aug 1, 2006):

Added Peripheral Nomad printer support

Version 3.550 (Mar 23, 2006):

Added Panasonic JT-H200PR printer support

Added Pocket Spectrum printer support

Fixed problem with WM5.0 "inverted image" problem

Send Email from SQL Server Express Using a CLR Stored Procedure

One of the nice things about SQL Server is the ability to send email using T-SQL. The downside is that this functionality does not exist in SQL Server Express. In this tip I will show you how to build a basic CLR stored procedure to send email messages from SQL Server Express, although this same technique could be used for any version of SQL Server.

If you have not yet built a CLR stored procedure, please refer to this tip for what needs to be done for the initial setup.

Sending a File Using Email Helper in WebPages/Razor


Note: This is particularly with respect to Email Helper in WebPages/Razor. Please don't post links using System.Net.Mail object.

Following this tutorial: http://www.asp.net/webmatrix/tutorials/9-adding-email-to-your-website

Under "Sending a File Using Email" section what exactly is the code trying to do.

1: The SendFile.cshtml does not have any option to select file.

2: ProcessFile.cshtml is running fine. I am getting the email but no attachement.

I tried changing fileAttachment input to type="file" but not file is being sent to my email. I just get the message send in body.

Question: How exactly this file attachment works using Email Helper in WebPages.

Linq - add data to database then email user the details


Hi all

I'm not sure how to structure the code for this but what I want to do is be able to add data to a database, and once this has completed successfully, then email the user to say the details have been added successfully to the database.

I need to:

1. Check that the relevant data has been added into the database then

2. Email the details of the relevant data when completed. 


Thanks in advance for your help,




Using CreateNewUserWizard SendingMail method to email me, not applicatnt.


I have staff area of my site I am protecting with forms authentication using c# and .Net 4.0. What I want to do is let the staff members register on the site but instead of the confermation email being sent to them I want it sent to me so I can go in and approve it. I have been trying to use the SendingMail method  but can not figure out how to get it to email me instead of the person that registered. I have searched around this site and find many topics on the SendingMail method but none seem to properly address my issue. Can anyone help me out?

How to send an email with information in query string


First I will say I googled (Binged to make Bill happy) for this but could not find anything, perhaps I am not stating what I need correctly;

I have a website that a customer creates orders (for a printing company) and after the order, I would like to email the customer a link to view the status of their order;

I need to send the CustomerID in the link so on the returning page if a CustomerID is detected in the querystring, I "auto login" the client and open the "Dashboard" for the order page for that customer.

Can anyone point me in the right direction as to how to send the link and how to parse the querystring to get the values from the link;

Thank you if you can point me in the right direction.

Fetching the Currently Logged in user Email


Hey Frnds,

I am using the System.DirectoryServices.UserPrincipal.Current.EmailAddress to fetch the Currently logged in users email from AD.

If  debug my sol am getting the Exact mail id of that Particular user for ex:john@in.domain.com.

If i host My Application on iis

And Access my App am getting some other Email id instead of the john@in.domain.com.

I have changed the Application Pool identity to NetWorkService.

Can any one tell what could be wrong




ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend