I just migrated an ASP.NET 4 application that sends an email attachment from a Win Server 2008 R2 to 2012. I'm using Visual Studio 2010 and when I debug the project works and I get the email with the attachment but this is through the localhost. I'm using a pod51008.outlook.com account in my smtp settings within the web.config and I can't get it send the email. Technically, I'm able to access the URL and login. Once I login I should be able to click button with the instructions to send email with attachment to my user account but instead I get my user-defined error message.
Here is the web.config file:
<system.net> <mailSettings> <smtp from="email@example.com"> <network host="pod51008.outlook.com" port="587" userName="firstname.lastname@example.org" password="password" enableSsl="true" /> </smtp> </mailSettings>
Here is the email subroutine code:
Private Sub email(ByVal att As String) Try Dim sendfrom As MailAddress = New MailAddress("email@example.com", "Email with attachment") Dim sendto As MailAddress = New MailAddress(EMP.Email) Dim attachmentFile As New Attachment(att) Dim mymessage As New MailMessage(sendfrom, sendto) With mymessage .Subject = "Email with attachment " .Body = "<br/></br/> Email message" .Attachments.Add(attachmentFile) .IsBodyHtml = True End With Dim smtpclient As New SmtpClient() smtpclient.EnableSsl = True smtpclient.Send(mymessage) Catch ex As Exception errormsg.Text = "Error Sending Email, please contact Help Desk" End Try errormsg.Text = "<div align='center'>An email has been sent to " & EMP.User_Email & ".</div><br/>" End Sub
SMTP is enabled within the Win Server 2012 I don't think I need this since I'm using the outlook account to send the email (please correct me if I'm mistaken). At least that's the way I had it in Win 2008 R2 and this was working properly.
I've been looking everywhere but all I could find where SMTP configurations to test within the server. Any help will be greatly appreciated!