Click here to Skip to main content
14,845,979 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: How do I insert a toggle switch value into sql database Pin
Richard Deeming27-Oct-16 2:15
mveRichard Deeming27-Oct-16 2:15 
QuestionHow to submit a record and send as an email attachment at once? Pin
samflex26-Oct-16 9:43
Membersamflex26-Oct-16 9:43 
AnswerRe: How to submit a record and send as an email attachment at once? Pin
ZurdoDev26-Oct-16 9:49
professionalZurdoDev26-Oct-16 9:49 
GeneralRe: How to submit a record and send as an email attachment at once? Pin
samflex26-Oct-16 10:34
Membersamflex26-Oct-16 10:34 
AnswerRe: How to submit a record and send as an email attachment at once? Pin
ZurdoDev26-Oct-16 11:49
professionalZurdoDev26-Oct-16 11:49 
GeneralRe: How to submit a record and send as an email attachment at once? Pin
samflex26-Oct-16 15:32
Membersamflex26-Oct-16 15:32 
GeneralRe: How to submit a record and send as an email attachment at once? Pin
ZurdoDev26-Oct-16 15:42
professionalZurdoDev26-Oct-16 15:42 
AnswerRe: How to submit a record and send as an email attachment at once? Pin
jkirkerx26-Oct-16 13:33
professionaljkirkerx26-Oct-16 13:33 
Ryandev is great at help if your question is very specific.

It may sound easy to do, but after time when the customer complains, you'll find yourself refining your code more and more to be 100% error free.

I'd start with writing several classes that is ...
  1. dedicated to updating the database
  2. dedicated to generating the PDF
  3. dedicated to sending emails
and then join the 3 together in your click function.
Then you can smooth out the process by making #2 & #3 async, sort of multitask in the background and quickly give the page back to the user while the email sends off.

I was going to post some code for you but my stuff is so customized now, it would be hard for you to follow. You won't be able to paste and go, but just look at it and wonder how it works.
I don't have anything generic anymore, that was years ago.

This is my send engine that I wrote. Years of evolution involved here for me.
Imports System.Net.Mail
Imports System.Threading.Tasks
Imports CO_Standard.Models
Imports System.Net
Imports System.Net.Security
Imports System.Configuration

Public Class sendEngineAsync

    Public Shared Function Create_SMTPClient(ByVal smtpC As hx5.common.structure_smtp_connector) As SmtpClient

        Dim smtpClient As New SmtpClient()

        smtpClient.UseDefaultCredentials = False
        smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network

        Select Case smtpClient.Port
            Case 587
                smtpClient.EnableSsl = False

            Case 443
                smtpClient.EnableSsl = True

            Case 25
                smtpClient.EnableSsl = False

            Case Else
                smtpClient.EnableSsl = False

        End Select

        Dim smtpCredentials = New Net.NetworkCredential
        smtpCredentials.UserName = smtpC.Credentials_LoginID
        smtpCredentials.Password = smtpC.Credentials_Password
        smtpClient.Credentials = smtpCredentials

        smtpClient.Host = smtpC.Connector_ServerAddress
        smtpClient.Port = smtpC.Connector_SMTP_PortNum
        smtpClient.Timeout = 250000

        Return smtpClient

    End Function
    Public Shared Async Function SendEmailAsync( _
        ByVal smtpClient As SmtpClient,
        ByVal message As MailMessage,
        ByVal retryCount As Integer) As Task(Of SendEmailCompletedEventArgs)

        Dim currentTry As Integer = 0
        While currentTry < retryCount

            Try

                Await smtpClient.SendMailAsync(message)
                Return New SendEmailCompletedEventArgs(Nothing, False, Nothing, currentTry)

            Catch ex As Exception

                currentTry += 1
                If currentTry >= retryCount Then
                    Return New SendEmailCompletedEventArgs(ex, True, Nothing, currentTry)
                End If

            End Try

        End While

        //Code should never reach here, but without this line you ll get a BC42105 warning:
        Return New SendEmailCompletedEventArgs(Nothing, True, Nothing, currentTry)

    End Function

This is sort of how you use the sendengine
Dim mailMessage As New MailMessage()
mailMessage.From = New MailAddress(smtpC.Options_WebsiteName & " < " & smtpC.Options_SentFrom & " >")
mailMessage.ReplyToList.Add(New MailAddress(smtpC.Options_ReplyTo))
mailMessage.To.Add(New MailAddress(names.firstName & " " & names.lastName & "<" & p.Email_Destination & ">"))
mailMessage.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure
mailMessage.IsBodyHtml = True
mailMessage.BodyEncoding = System.Text.Encoding.UTF8
mailMessage.Priority = MailPriority.High
mailMessage.Subject = m_Subject & " - " & DateTime.Now.ToLongTimeString()
mailMessage.SubjectEncoding = System.Text.Encoding.UTF8

Using SmtpClient As SmtpClient = sendEngine.Create_SMTPClient(smtpC)

   Dim result As SendEmailCompletedEventArgs = sendEngine.SendEmail(SmtpClient, mailMessage, p.retryCount)
   sendEngineAsync.ProcessSendResult(model, result, pValue)

End Using

smtpC is a model that stores credentials for sending the email message, you would have to make your own model.
GeneralRe: How to submit a record and send as an email attachment at once? Pin
samflex26-Oct-16 15:41
Membersamflex26-Oct-16 15:41 
GeneralRe: How to submit a record and send as an email attachment at once? Pin
jkirkerx27-Oct-16 7:06
professionaljkirkerx27-Oct-16 7:06 
GeneralRe: How to submit a record and send as an email attachment at once? Pin
samflex27-Oct-16 8:12
Membersamflex27-Oct-16 8:12 
GeneralRe: How to submit a record and send as an email attachment at once? Pin
jkirkerx27-Oct-16 11:36
professionaljkirkerx27-Oct-16 11:36 
GeneralRe: How to submit a record and send as an email attachment at once? Pin
samflex27-Oct-16 15:11
Membersamflex27-Oct-16 15:11 
QuestionPOST xml request to an API with feedback asp.net mvc Pin
MacroSss21-Oct-16 0:11
MemberMacroSss21-Oct-16 0:11 
AnswerRe: POST xml request to an API with feedback asp.net mvc Pin
jkirkerx24-Oct-16 9:15
professionaljkirkerx24-Oct-16 9:15 
AnswerRe: POST xml request to an API with feedback asp.net mvc Pin
MacroSss26-Oct-16 1:23
MemberMacroSss26-Oct-16 1:23 
GeneralRe: POST xml request to an API with feedback asp.net mvc Pin
MacroSss26-Oct-16 1:24
MemberMacroSss26-Oct-16 1:24 
QuestionThere is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'SelectedClientList'. Pin
amioni20-Oct-16 1:43
Memberamioni20-Oct-16 1:43 
AnswerRe: There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'SelectedClientList'. Pin
jkirkerx20-Oct-16 8:57
professionaljkirkerx20-Oct-16 8:57 
QuestionHow to save modal popup form into database/data table Pin
Bootzilla3319-Oct-16 10:47
MemberBootzilla3319-Oct-16 10:47 
AnswerRe: How to save modal popup form into database/data table Pin
Sahil Saini @ Software Developer19-Oct-16 19:23
professionalSahil Saini @ Software Developer19-Oct-16 19:23 
Questioni want fill 2 table with 1 click can I? Pin
moj197817-Oct-16 9:00
Membermoj197817-Oct-16 9:00 
AnswerRe: i want fill 2 table with 1 click can I? Pin
Vincent Maverick Durano17-Oct-16 9:07
professionalVincent Maverick Durano17-Oct-16 9:07 
GeneralRe: i want fill 2 table with 1 click can I? Pin
moj197817-Oct-16 9:13
Membermoj197817-Oct-16 9:13 
GeneralRe: i want fill 2 table with 1 click can I? Pin
Vincent Maverick Durano17-Oct-16 9:17
professionalVincent Maverick Durano17-Oct-16 9:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.