1
Reply

serious issues with emailing from asp.net

Ricardo Carvalho

Ricardo Carvalho

Mar 25 2008 5:39 AM
2.3k
Hi all.

I am having a whole lot of trouble trying to send an email from my website application.

of the many different methods that I have tried, here are a few two of them which were the best two thus far with the results recieved from each method.

This first thing that I tried was to use the Outlook option:

            //create the mail message
            MailMessage mail = new MailMessage();

            //set the addresses
            mail.From = new MailAddress("[email protected]");
            mail.To.Add(strTo);

            //set the content
            mail.Subject = strSubject;
            mail.Body = strBody;
            mail.IsBodyHtml = true;

            //send the message
            SmtpClient smtp = new SmtpClient("xxx.xxx.x.xx");
            smtp.Send(mail);

            Application oApp = new Application();
            NameSpace oNS = oApp.GetNamespace("mapi");
            oNS.Logon(null, null, true, true);

            _MailItem oMsg = (_MailItem)oApp.CreateItem(OlItemType.olMailItem);
            oMsg.Subject = strSubject;
            oMsg.HTMLBody = strBody;
            Recipients oRecips = (Recipients)oMsg.Recipients;
            Recipient oRecip = (Recipient)oRecips.Add(strTo);
            oRecip.Resolve();
            oMsg.Send();
            oNS.Logoff();
            oRecip = null;
            oRecips = null;
            oMsg = null;
            oNS = null;
            oApp = null;

This worked very well. On my local machine that is, because then I was able to get the Visual Studio runtime to plug in to my running version of the Outlook. Outlook is connected to an exchange server btw.
The noreply account is an existing user in the DHCP user accounts and it sends the emails succesfully during the testing on my machine. However, it did not send it from noreply, it sent it from my own account. So what I did was I set outlook up on the server and defaulted it to connect the noreply account on exchange. One problem though, I could not get the code to open the outlook instance and send the email. If there is anyone that can help me with that issue, it would be greatly appreciated.

Then, the second option that I have tried which proved semi successfull is this:

MailMessage message = new MailMessage();

            message.From = new MailAddress("[email protected]");
            message.To.Add(new MailAddress(strTo));
            message.Subject = "Re: " + strSubject;
            message.Body = strBody;

            message.IsBodyHtml = true;

            SmtpClient client = new SmtpClient();

            client.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
            client.Send(message);

I have this in my web.config:

<system.net>
        <mailSettings>
            <smtp>
                <network host="xxx.xxx.x.xx" port="25" userName="[email protected]" password="password"/>
            </smtp>
        </mailSettings>
    </system.net>

This generally works from both local testing as well as from the server, however I have issues with it still. It lands up in spam folders, or it doesn't get deliverd to some of the people.

I found during a lot of googling that if you suffix the Subject with "Re: ", that takes it out of the junk folder on the other side. (it works). but now, here is my problem, we are running dynamic IP addresses on our outgoing adsl line. So our IP address is forever changing and this is the response that I am getting from most of the smtp servers which I am trying to send to:

[email protected] not allowed - 5.7.1 [BL21] Connections not accepted from IP addresses on Spamhaus PBL; see http://postmaster.yahoo.com/550-bl21.html [550]>


I read that link and it says that it basically doesn't like the dynamic email thing. there are some servers which accept my emails. Our internal site is one of them. Gmail is the other. there are also some companies that do accept it. but as for the others, what can I do.

If there is any one that can help me to get the emails to travel to all smtp servers, that would be awesome.

Answers (1)
Next Recommended Forum