11 messaggi dal 24 marzo 2006
Ciao a tutti avendo questo codice:

<%
dim a_messages
dim a_attachments

function SendMail(mailserver, recipient_name, recipient_address, sender_name, sender_address, subject, body)

  dim a_recipient_address
  dim a_recipient_name

  if mailserver = "" or isnull(mailserver) then mailserver = application("smtp_server")

  if sender_name = "" or isnull(sender_name) then sender_name = application("from_name")
  if sender_address = "" or isnull(sender_address) then sender_address = application("from_address")



  select case application("email_component")
case "cdosys"
set mail = Server.CreateObject("CDO.Message")
  set mailcon = Server.CreateObject ("CDO.Configuration")

  
  With mailcon
  
  'SMTP server
  .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.aruba.it"

  'SMTP port
  .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

  'CDO Port
  .Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

  'timeout
  .Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Fields.Update 

  End With
  
  Set mail.Configuration = mailcon

  With mail
  .From = sender_address
  .To = recipient_address

  .Subject = subject
  .HTMLBody = body

end with
  
  '' send the mail
  on error resume next
  mail.Send
  if Err.Number = 0 then
    sendmail = 1
  else
    sendmail = -1
  end if
  on error goto 0

  end select
    
end function

function SendAppEmail(message_id, user_param, user_cc_param, keyfield_param)

  dim rs, sql
  dim subject, body
  dim i
  
  send_count = 0

ecc.....
non riesco a capire perchè non invia l'email premetto che il server su cui risiede è Aruba, alcuni mi hanno detto che l'errore sta nel non aver specificato l'indirizzo dell'email qui:
Set mail.Configuration = mailcon

  With mail
  .From = sender_address
  .To = recipient_address

  .Subject = subject
  .HTMLBody = body
end with
ma dato che sono a zero di asp, non saprei dove mettere le mani,mi affido alla vostra bravura nella speranza che riesca a mandare questa email.
Grazie !
394 messaggi dal 11 agosto 2004
prova con questo:
sub inviomail(nomemittente,mittente,destinatario,oggetto,username,password)
Set objMessage = Server.CreateObject("CDO.Message")
Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")
Set objMessage.Configuration = objCDOSYSCon
With objMessage
.Configuration.Fields("urn:schemas:httpmail:importance").Value = 1
.Configuration.fields("urn:schemas:mailheader:read-receipt-notification-to") = mittente
.Configuration.fields("urn:schemas:mailheader:disposition-notification-to") = mittente
.Configuration.fields("urn:schemas:mailheader:return-receipt-to") = mittente
.Configuration.fields.update
.DSNOptions = 14
.MDNRequested = true
.DSNOptions = cdoDSNSuccessFailOrDelay
.To = mails
.From = nomemittente & "<" & mittente & ">"
.subject = oggetto
.HTMLBody = QUI INSERISCI IL TESTO DELLA MAIL IN HTML
bjMessage.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/urlgetlatestversion") = True
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.aruba.it"
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = username
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = password
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objMessage.Configuration.Fields.Update
.fields.update
.send
End Sub

inviomail(Gigi,gigi@gigi.it,luigino@luigino.it,ciao come va?,aruba,aruba)
11 messaggi dal 24 marzo 2006
Mi dà errore...
il problema è che non sono sicura di aver incollato al posto giusto il tuo codice non so se avevo premesso che questo codice da me postato si riferisce ad uno script
per forum ed ha la funzione di inviare l'email a chi l'ha dimenticata.
Posto tutto il codice della pagina così puoi inserire il tuo al posto giusto:
<%
dim a_messages
dim a_attachments

function SendMail(mailserver, recipient_name, recipient_address, sender_name, sender_address, subject, body)

dim a_recipient_address
dim a_recipient_name

if mailserver = "" or isnull(mailserver) then mailserver = application("smtp_server")

if sender_name = "" or isnull(sender_name) then sender_name = application("from_name")
if sender_address = "" or isnull(sender_address) then sender_address = application("from_address")



select case application("email_component")
case "cdosys"
set mail = Server.CreateObject("CDO.Message")
set mailcon = Server.CreateObject ("CDO.Configuration")


With mailcon

'SMTP server
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.aruba.it"

'SMTP port
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

'CDO Port
.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

'timeout
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Fields.Update

End With

Set mail.Configuration = mailcon

With mail
.From = sender_address
.To = recipient_address

.Subject = subject
.HTMLBody = body

end with

'' send the mail
on error resume next
mail.Send
if Err.Number = 0 then
sendmail = 1
else
sendmail = -1
end if
on error goto 0

end select

end function

function SendAppEmail(message_id, user_param, user_cc_param, keyfield_param)

dim rs, sql
dim subject, body
dim i

send_count = 0 

set rs = cn.Execute("SELECT body, subject, send_to_custom, sql_user_query, sql_user_cc_query, sql_vars_query FROM Newsletters WHERE newsletter_id =" & to_sql(message_id,"number"))
  if not rs.EOF then
    body = rs("body")
    subject = rs("subject")
    send_to_custom = rs("send_to_custom")
    recipients_sql = rs("sql_user_query")
    cc_recipients_sql = rs("sql_user_cc_query")
    vars_sql = rs("sql_vars_query")
  else
    b_error=true
    error_list.add "nomessage", "The newsletter (message) #" & message_id & "does not exist."
    SendAppEmail = -1
    exit function
  end if
  rs.Close
  
  ':: select user list from passed recipient user_param
  if len(user_param)>0 AND not isnull(recipients_sql) then recipients_sql = replace(recipients_sql,"?",user_param)

    
  ':: open recordset that contains message variables ::::::::::::::::::::::::::::::::::
  if len(vars_sql)>0 then
  
  vars_sql = replace(vars_sql,"?",keyfield_param)
  set rs = cn.Execute(vars_sql)
  if rs.EOF then
    b_error=true
    error_list.add "novarsrs", "Variable recordset could not be created. Please check the variable SQL query and parameter value."
    exit function
  else
    
  ':: repeating vars in body?
  if inStr(body,"{|b|}")>0 AND inStr(body,"{|e|}")>0 then
    start_body = left(body,inStr(body,"{|b|}")-1)
    end_body = right(body,(len(body)-inStr(body,"{|e|}")-4))
  
    ':: repeating row
    length = inStr(body,"{|e|}")-inStr(body,"{|b|}")-5
    repeating_row = mid(body,inStr(body,"{|b|}")+5,length)
  else
    start_body = body
    end_body = ""
  end if
    
  do until rs.EOF
    ':: contruct body by replacing each variable
    ':: in message body with field value
    tmp_buf = repeating_row
    for i = 0 to rs.Fields.Count-1
      V = rs.Fields(i).value
      N = rs.Fields(i).name
      if isNull(V) then V=""  
      tmp_buf = replace(tmp_buf,"{|"&N&"|}",V)
      start_body = replace(start_body,"{|"&N&"|}",V)
      end_body = replace(end_body,"{|"&N&"|}",V)
      subject = replace(subject,"{|"&N&"|}",V)
    next
    mid_body = mid_body & tmp_buf
  rs.MoveNext
  loop
  end if
  rs.Close
    
  body = start_body & mid_body & end_body
    
  end if
  '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  
  
  ':: replace application vars in message :::::::::::::::::::::::::::::
  aTmp = array("site_label","site_title","site_root","secure_site_root","from_address","from_name")
  for each thing in aTmp
    if isNull(application(thing)) then application(thing) = ""
    body = replace(body,"{|"&thing&"|}",application(thing))
    subject = replace(subject,"{|"&thing&"|}",application(thing))
  next
  ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  

  ':: send to custom list
  if len(send_to_custom)>1 then
  
  a_sendlist = split(send_to_custom,",")
  for i = 0 to uBound(a_sendlist)
  
    tmp_buf = body
    recipient_name = a_sendlist(i)
    recipient_address = recipient_name
    
    ':: add user if email doesn't exist in database
    set rs = cn.Execute("SELECT user_id, user_name, email FROM Users WHERE email=" & to_sql(recipient_address,"text"))
    if rs.EOF then cn.Execute("INSERT INTO Users (email, accesslevel) VALUES (" & to_sql(recipient_address,"text") & ", 0)")  
    tmp_buf = replace(tmp_buf,"{|user_name|}",recipient_name)
    tmp_buf = replace(tmp_buf,"{|email|}",recipient_address)

    ':: send the mail
    retv = SendMail(NULL, recipient_name, recipient_address, sender_name, sender_address, subject, tmp_buf)
    if retv = 1 then send_count = send_count + 1

  next
  end if

  ':: open recipients recordset and send to each recipient
  if len(recipients_sql)>0 then
  'response.write recipients_sql
  set rs = cn.Execute(recipients_sql)
  do until rs.EOF
  
    tmp_body = body
    tmp_subject = subject
    user_name = rs("user_name")
    email = rs("email")
    if isNull(user_name) or user_name="" then user_name=email
    ':: replace any user vars in mail message
    tmp_buf = replace(tmp_buf,"{|user_name|}",user_name)
    tmp_buf = replace(tmp_buf,"{|email|}",email)
    
    for i = 0 to rs.Fields.Count-1
        V = rs.Fields(i).value
        N = rs.Fields(i).name
        if isNull(V) then V=""  
        tmp_body = replace(tmp_body,"{|"&N&"|}",V)
        tmp_subject = replace(tmp_subject,"{|"&N&"|}",V)
    next    
    
    retv = SendMail(null, user_name, email, application("from_name"), application("from_address"), tmp_subject, tmp_body)
    ':: uncomment the line below to display recipients
    'if retv=1 then msg_list.add "to" & send_count, email
    if retv=1 then send_count = send_count + 1
  rs.MoveNext
  loop
  rs.Close
  
  end if
  
  ':: open cc recipients recordset and send to each cc recipient
  if len(cc_recipients_sql)>0 then
  
  if not isNull(user_cc_param) then cc_recipients_sql = replace(cc_recipients_sql,"?",user_cc_param)
  
  if inStr(cc_recipients_sql,"?")=0 then
  set rs = cn.Execute(cc_recipients_sql)
  do until rs.EOF
    user_name = rs("user_name")
    email = rs("email")
    if isNull(user_name) or user_name="" then user_name=email
    ':: replace any user vars in mail message
    body = replace(body,"{|user_name|}",user_name)
    body = replace(body,"{|email|}",email)
    retv = SendMail(null, user_name, email, application("from_name"), application("from_address"), subject, body)
    ':: uncomment the line below to display cc recipients
    'if retv=1 then msg_list.add "to" & send_count, email
    if retv=1 then send_count = send_count + 1
  rs.MoveNext
  loop
  rs.Close
  end if
  
  end if
  
  ':: return
  SendAppEMail = send_count

end function


function CheckMail(mailserver, username, password)
  '::::::::::::::::::::::::::::::::::::::::::
  ':: checks for new messages on server 
  ':: stores data in gloabl message and attachment arrays

  dim i_msgs

  set mail = Server.CreateObject("JMail.POP3")
  'on error resume next
  mail.connect username, password, mailserver
  
  if err.number <> 0 then 
    checkmail = -1
    exit function
  end if
  
  i_msgs = mail.Count
  redim a_messages(6,i_msgs)
  
  for i = i_msgs to 1 step -1
    'get messages
    set msg = mail.Messages.item(i)
    a_messages(0,i) = msg.ContentType
    a_messages(1,i) = msg.From
    a_messages(2,i) = msg.FromName
    a_messages(3,i) = msg.Subject
    a_messages(4,i) = msg.Date
    a_messages(5,i) = msg.Size
    a_messages(6,i) = msg.Attachments.Count
    if a_messages(6,i) > 0 then
      'get attachments
      redim a_attachments(4,a_messages(6,i)-1)
      for j = 0 to uBound(a_attachments)
        set attach = msg.Attachments.item(j+1)
        a_attachments(0,j) = attach.ContentType
           a_attachments(1,j) = attach.isInline
        a_attachments(2,j) = attach.Name
        a_attachments(3,j) = attach.Size
      next
    end if
  next
  
  checkmail = i_msgs
  
  mail.disconnect
  set mail = nothing
  
end function

%>
394 messaggi dal 11 agosto 2004
non so se hai risolto ma non mi hai mai detto che errore ti da!
Comunque il problema potrebbe essere che alla fine usi un compnente JMAIL.. sicusa che Aruba lo supporti? Informati! :)
Prova con questo codice:
<%
dim a_messages
dim a_attachments

function SendMail(mailserver, recipient_name, recipient_address, sender_name, sender_address, subject, body)

dim a_recipient_address
dim a_recipient_name

if mailserver = "" or isnull(mailserver) then mailserver = application("smtp_server")

if sender_name = "" or isnull(sender_name) then sender_name = application("from_name")
if sender_address = "" or isnull(sender_address) then sender_address = application("from_address")



select case application("email_component")
case "cdosys"
set mail = Server.CreateObject("CDO.Message")
set mailcon = Server.CreateObject ("CDO.Configuration")


With mailcon
.Fields("http://schemas.microsoft.com/cdo/configuration/urlgetlatestversion") = True
' NOME UTENTE
.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = username
'PASSWORD
.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = password
.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
'SMTP server
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.aruba.it"

'SMTP port
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

'CDO Port
.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

'timeout
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Fields.Update

End With

Set mail.Configuration = mailcon

With mail
.From = sender_address
.To = recipient_address

.Subject = subject
.HTMLBody = body

end with

'' send the mail
on error resume next
mail.Send
if Err.Number = 0 then
sendmail = 1
else
sendmail = -1
end if
on error goto 0

end select

end function

function SendAppEmail(message_id, user_param, user_cc_param, keyfield_param)

dim rs, sql
dim subject, body
dim i

send_count = 0

set rs = cn.Execute("SELECT body, subject, send_to_custom, sql_user_query, sql_user_cc_query, sql_vars_query FROM Newsletters WHERE newsletter_id =" & to_sql(message_id,"number"))
if not rs.EOF then
body = rs("body")
subject = rs("subject")
send_to_custom = rs("send_to_custom")
recipients_sql = rs("sql_user_query")
cc_recipients_sql = rs("sql_user_cc_query")
vars_sql = rs("sql_vars_query")
else
b_error=true
error_list.add "nomessage", "The newsletter (message) #" & message_id & "does not exist."
SendAppEmail = -1
exit function
end if
rs.Close

':: select user list from passed recipient user_param
if len(user_param)>0 AND not isnull(recipients_sql) then recipients_sql = replace(recipients_sql,"?",user_param)


':: open recordset that contains message variables ::::::::::::::::::::::::::::::::::
if len(vars_sql)>0 then

vars_sql = replace(vars_sql,"?",keyfield_param)
set rs = cn.Execute(vars_sql)
if rs.EOF then
b_error=true
error_list.add "novarsrs", "Variable recordset could not be created. Please check the variable SQL query and parameter value."
exit function
else

':: repeating vars in body?
if inStr(body,"{|b|}")>0 AND inStr(body,"{|e|}")>0 then
start_body = left(body,inStr(body,"{|b|}")-1)
end_body = right(body,(len(body)-inStr(body,"{|e|}")-4))

':: repeating row
length = inStr(body,"{|e|}")-inStr(body,"{|b|}")-5
repeating_row = mid(body,inStr(body,"{|b|}")+5,length)
else
start_body = body
end_body = ""
end if

do until rs.EOF
':: contruct body by replacing each variable
':: in message body with field value
tmp_buf = repeating_row
for i = 0 to rs.Fields.Count-1
V = rs.Fields(i).value
N = rs.Fields(i).name
if isNull(V) then V=""
tmp_buf = replace(tmp_buf,"{|"&N&"|}",V)
start_body = replace(start_body,"{|"&N&"|}",V)
end_body = replace(end_body,"{|"&N&"|}",V)
subject = replace(subject,"{|"&N&"|}",V)
next
mid_body = mid_body & tmp_buf
rs.MoveNext
loop
end if
rs.Close

body = start_body & mid_body & end_body

end if
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


':: replace application vars in message :::::::::::::::::::::::::::::
aTmp = array("site_label","site_title","site_root","secure_site_root","from_address","from_name")
for each thing in aTmp
if isNull(application(thing)) then application(thing) = ""
body = replace(body,"{|"&thing&"|}",application(thing))
subject = replace(subject,"{|"&thing&"|}",application(thing))
next
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


':: send to custom list
if len(send_to_custom)>1 then

a_sendlist = split(send_to_custom,",")
for i = 0 to uBound(a_sendlist)

tmp_buf = body
recipient_name = a_sendlist(i)
recipient_address = recipient_name

':: add user if email doesn't exist in database
set rs = cn.Execute("SELECT user_id, user_name, email FROM Users WHERE email=" & to_sql(recipient_address,"text"))
if rs.EOF then cn.Execute("INSERT INTO Users (email, accesslevel) VALUES (" & to_sql(recipient_address,"text") & ", 0)")
tmp_buf = replace(tmp_buf,"{|user_name|}",recipient_name)
tmp_buf = replace(tmp_buf,"{|email|}",recipient_address)

':: send the mail
retv = SendMail(NULL, recipient_name, recipient_address, sender_name, sender_address, subject, tmp_buf)
if retv = 1 then send_count = send_count + 1

next
end if

':: open recipients recordset and send to each recipient
if len(recipients_sql)>0 then
'response.write recipients_sql
set rs = cn.Execute(recipients_sql)
do until rs.EOF

tmp_body = body
tmp_subject = subject
user_name = rs("user_name")
email = rs("email")
if isNull(user_name) or user_name="" then user_name=email
':: replace any user vars in mail message
tmp_buf = replace(tmp_buf,"{|user_name|}",user_name)
tmp_buf = replace(tmp_buf,"{|email|}",email)

for i = 0 to rs.Fields.Count-1
V = rs.Fields(i).value
N = rs.Fields(i).name
if isNull(V) then V=""
tmp_body = replace(tmp_body,"{|"&N&"|}",V)
tmp_subject = replace(tmp_subject,"{|"&N&"|}",V)
next

retv = SendMail(null, user_name, email, application("from_name"), application("from_address"), tmp_subject, tmp_body)
':: uncomment the line below to display recipients
'if retv=1 then msg_list.add "to" & send_count, email
if retv=1 then send_count = send_count + 1
rs.MoveNext
loop
rs.Close

end if

':: open cc recipients recordset and send to each cc recipient
if len(cc_recipients_sql)>0 then

if not isNull(user_cc_param) then cc_recipients_sql = replace(cc_recipients_sql,"?",user_cc_param)

if inStr(cc_recipients_sql,"?")=0 then
set rs = cn.Execute(cc_recipients_sql)
do until rs.EOF
user_name = rs("user_name")
email = rs("email")
if isNull(user_name) or user_name="" then user_name=email
':: replace any user vars in mail message
body = replace(body,"{|user_name|}",user_name)
body = replace(body,"{|email|}",email)
retv = SendMail(null, user_name, email, application("from_name"), application("from_address"), subject, body)
':: uncomment the line below to display cc recipients
'if retv=1 then msg_list.add "to" & send_count, email
if retv=1 then send_count = send_count + 1
rs.MoveNext
loop
rs.Close
end if

end if

':: return
SendAppEMail = send_count

end function


function CheckMail(mailserver, username, password)
'::::::::::::::::::::::::::::::::::::::::::
':: checks for new messages on server
':: stores data in gloabl message and attachment arrays

dim i_msgs

set mail = Server.CreateObject("JMail.POP3")
'on error resume next
mail.connect username, password, mailserver

if err.number <> 0 then
checkmail = -1
exit function
end if

i_msgs = mail.Count
redim a_messages(6,i_msgs)

for i = i_msgs to 1 step -1
'get messages
set msg = mail.Messages.item(i)
a_messages(0,i) = msg.ContentType
a_messages(1,i) = msg.From
a_messages(2,i) = msg.FromName
a_messages(3,i) = msg.Subject
a_messages(4,i) = msg.Date
a_messages(5,i) = msg.Size
a_messages(6,i) = msg.Attachments.Count
if a_messages(6,i) > 0 then
'get attachments
redim a_attachments(4,a_messages(6,i)-1)
for j = 0 to uBound(a_attachments)
set attach = msg.Attachments.item(j+1)
a_attachments(0,j) = attach.ContentType
a_attachments(1,j) = attach.isInline
a_attachments(2,j) = attach.Name
a_attachments(3,j) = attach.Size
next
end if
next

checkmail = i_msgs

mail.disconnect
set mail = nothing

end function

%>

Modificato da Maxiz il 27 settembre 2007 10.58 -

Torna al forum | Feed RSS

ASPItalia.com non è responsabile per il contenuto dei messaggi presenti su questo servizio, non avendo nessun controllo sui messaggi postati nei propri forum, che rappresentano l'espressione del pensiero degli autori.